From 0927dcbbb8c9f1a150502cca01086c1a462ba04f Mon Sep 17 00:00:00 2001 From: Diego Cardoso Date: Wed, 2 Dec 2020 15:35:59 +0200 Subject: [PATCH] feat: Edit on Click (#151) Add ability to make cell edition to be performed on a single click part of #73 Co-authored-by: Tomi Virkki --- .travis.yml | 2 +- demo/grid-pro-edit-column-demos.html | 23 +++++++++++++++++++ src/vaadin-grid-pro-inline-editing-mixin.html | 15 +++++++++++- test/edit-column-renderer.html | 17 ++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d144054..f9d95c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ sudo: false dist: xenial language: node_js -node_js: 8.11 +node_js: 10.23 cache: directories: diff --git a/demo/grid-pro-edit-column-demos.html b/demo/grid-pro-edit-column-demos.html index ee103fd..756e7cd 100644 --- a/demo/grid-pro-edit-column-demos.html +++ b/demo/grid-pro-edit-column-demos.html @@ -128,6 +128,29 @@

Single Cell Edit

+

Edit on Click

+

+ When editOnClick is set on the grid element, cell edit mode gets activated on a single click + instead of the default double click. +

+ + + +

Use Enter to Focus Next Row

When enterNextRow is set on the grid element, the following keys change behavior: diff --git a/src/vaadin-grid-pro-inline-editing-mixin.html b/src/vaadin-grid-pro-inline-editing-mixin.html index 9912b5c..e57c9da 100644 --- a/src/vaadin-grid-pro-inline-editing-mixin.html +++ b/src/vaadin-grid-pro-inline-editing-mixin.html @@ -47,6 +47,14 @@ notify: true // FIXME(yuriy-fix): needed by Flow counterpart }, + /** + * When true, the grid enters cell edit mode on a single click + * instead of the default double click. + */ + editOnClick: { + type: Boolean, + }, + /** @private */ _editingDisabled: { type: Boolean @@ -104,6 +112,9 @@ const column = this.getEventContext(e).column; if (column && this._isEditColumn(column)) { e.preventDefault(); + if (this.editOnClick) { + this._enterEditFromEvent(e); + } } }); @@ -131,7 +142,9 @@ }); } else { this.addEventListener('dblclick', e => { - this._enterEditFromEvent(e); + if (!this.editOnClick) { + this._enterEditFromEvent(e); + } }); } } diff --git a/test/edit-column-renderer.html b/test/edit-column-renderer.html index 1176d1d..1e63713 100644 --- a/test/edit-column-renderer.html +++ b/test/edit-column-renderer.html @@ -165,6 +165,23 @@ const secondCell = getContainerCell(grid.$.items, 0, 2); expect(secondCell._content.textContent).to.equal('new'); }); + + describe('single click edit', () => { + + beforeEach(() => grid.editOnClick = true); + + it('should enter edit mode on single click', () => { + firstCell._content.dispatchEvent(new CustomEvent('click', {bubbles: true, composed: true})); + expect(getCellEditor(firstCell)).to.be.ok; + }); + + it('should not enter edit mode on single click', () => { + grid.editOnClick = false; + firstCell._content.dispatchEvent(new CustomEvent('click', {bubbles: true, composed: true})); + expect(getCellEditor(firstCell)).not.to.be.ok; + }); + + }); }); describe('custom edit mode renderer', () => {