Skip to content

Commit 212637f

Browse files
ugur-vaadinvursen
andauthored
fix: focus editor only after it is ready (#7235)
* fix: defer focus in order to have editor ready before * test: fix unit test for firefox * test: await next render before assertion * test: add another await next render after the first keydown * Revert "test: add another await next render after the first keydown" This reverts commit 3a62f57. * Revert "test: await next render before assertion" This reverts commit d5939d1. * test: update material visual test reference image * fix: set edit initiator char explicitly * test: revert skip test * fix: do not select input when initialized with character * Update packages/grid-pro/test/edit-column-type.common.js Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com> * refactor: extract input selection logic from editor focus * refactor: change name of the new property * refactor: focus lit editor once it is ready * test: revert unnecessary awaits * test: revery unnecessary test assertion changes * Revert "test: update material visual test reference image" This reverts commit f180f2b. * test: skip new test on firefox * test: revert test skip change * Update packages/grid-pro/test/edit-column-type.common.js Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com> --------- Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
1 parent d3f0ed0 commit 212637f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

packages/grid-pro/src/vaadin-grid-pro-edit-column-mixin.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,11 @@ export const GridProEditColumnMixin = (superClass) =>
267267
this._setEditorValue(editor, get(this.path, model.item));
268268
editor._grid = this._grid;
269269

270-
this._focusEditor(editor);
271-
requestAnimationFrame(() => this._focusEditor(editor));
270+
if (editor.updateComplete) {
271+
editor.updateComplete.then(() => this._focusEditor(editor));
272+
} else {
273+
this._focusEditor(editor);
274+
}
272275
}
273276

274277
/**

packages/grid-pro/test/edit-column-type.common.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import {
66
fixtureSync,
77
focusin,
88
focusout,
9+
isFirefox,
910
keyDownChar,
1011
nextFrame,
1112
nextRender,
1213
space,
1314
} from '@vaadin/testing-helpers';
15+
import { sendKeys } from '@web/test-runner-commands';
1416
import sinon from 'sinon';
1517
import { createItems, dblclick, flushGrid, getCellEditor, getContainerCell, onceOpened } from './helpers.js';
1618

@@ -97,8 +99,9 @@ describe('edit column editor type', () => {
9799
expect(checkbox.checked).to.be.equal(grid.items[0].married);
98100
});
99101

100-
it('should set focus-ring on the checkbox', () => {
102+
it('should set focus-ring on the checkbox', async () => {
101103
dblclick(cell._content);
104+
await nextFrame();
102105
checkbox = column._getEditorComponent(cell);
103106
expect(checkbox.hasAttribute('focus-ring')).to.be.true;
104107
});
@@ -362,5 +365,15 @@ describe('edit column editor type', () => {
362365
editor = column._getEditorComponent(cell);
363366
expect(editor).to.be.not.ok;
364367
});
368+
369+
(isFirefox ? it.skip : it)('should not start edit with first character selected', async () => {
370+
column = grid.querySelector('[path="name"]');
371+
cell = getContainerCell(grid.$.items, 0, columns.indexOf(column));
372+
cell.focus();
373+
await sendKeys({ down: 'a' });
374+
await sendKeys({ down: 'b' });
375+
await sendKeys({ down: 'Enter' });
376+
expect(cell._content.textContent).to.equal('ab');
377+
});
365378
});
366379
});

0 commit comments

Comments
 (0)