Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: focus editor only after it is ready #7235

Merged
merged 20 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3abaf85
fix: defer focus in order to have editor ready before
ugur-vaadin Mar 18, 2024
cfb7887
test: fix unit test for firefox
ugur-vaadin Mar 18, 2024
b128cc2
test: await next render before assertion
ugur-vaadin Mar 18, 2024
fe49083
test: add another await next render after the first keydown
ugur-vaadin Mar 18, 2024
727a168
Revert "test: add another await next render after the first keydown"
ugur-vaadin Mar 18, 2024
83081e5
Revert "test: await next render before assertion"
ugur-vaadin Mar 18, 2024
f180f2b
test: update material visual test reference image
ugur-vaadin Mar 19, 2024
7a7ba81
fix: set edit initiator char explicitly
ugur-vaadin Mar 22, 2024
80b35d7
test: revert skip test
ugur-vaadin Mar 22, 2024
0df8bde
fix: do not select input when initialized with character
ugur-vaadin Mar 22, 2024
1c27e3b
Update packages/grid-pro/test/edit-column-type.common.js
ugur-vaadin Mar 22, 2024
558ae39
refactor: extract input selection logic from editor focus
ugur-vaadin Mar 26, 2024
774cb53
refactor: change name of the new property
ugur-vaadin Mar 26, 2024
750fe4e
refactor: focus lit editor once it is ready
ugur-vaadin Mar 27, 2024
bde29e2
test: revert unnecessary awaits
ugur-vaadin Mar 27, 2024
d82353d
test: revery unnecessary test assertion changes
ugur-vaadin Mar 27, 2024
44c453a
Revert "test: update material visual test reference image"
ugur-vaadin Mar 27, 2024
c3136e9
test: skip new test on firefox
ugur-vaadin Mar 27, 2024
74277ad
test: revert test skip change
ugur-vaadin Mar 27, 2024
8ea9a52
Update packages/grid-pro/test/edit-column-type.common.js
ugur-vaadin Mar 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/grid-pro/src/vaadin-grid-pro-edit-column-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,11 @@ export const GridProEditColumnMixin = (superClass) =>
this._setEditorValue(editor, get(this.path, model.item));
editor._grid = this._grid;

this._focusEditor(editor);
requestAnimationFrame(() => this._focusEditor(editor));
if (editor.updateComplete) {
editor.updateComplete.then(() => this._focusEditor(editor));
} else {
this._focusEditor(editor);
}
}

/**
Expand Down
15 changes: 14 additions & 1 deletion packages/grid-pro/test/edit-column-type.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import {
fixtureSync,
focusin,
focusout,
isFirefox,
keyDownChar,
nextFrame,
nextRender,
space,
} from '@vaadin/testing-helpers';
import { sendKeys } from '@web/test-runner-commands';
import sinon from 'sinon';
import { createItems, dblclick, flushGrid, getCellEditor, getContainerCell, onceOpened } from './helpers.js';

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

it('should set focus-ring on the checkbox', () => {
it('should set focus-ring on the checkbox', async () => {
dblclick(cell._content);
await nextFrame();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary because of the timing changes.

checkbox = column._getEditorComponent(cell);
expect(checkbox.hasAttribute('focus-ring')).to.be.true;
});
Expand Down Expand Up @@ -362,5 +365,15 @@ describe('edit column editor type', () => {
editor = column._getEditorComponent(cell);
expect(editor).to.be.not.ok;
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New test fails here with Firefox, works locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried the fix manually for both Lit and Polymer, using all supported browsers on MacOS, Windows, and Android. The issue does not seem to be re reproducible in any of them.

(isFirefox ? it.skip : it)('should not start edit with first character selected', async () => {
column = grid.querySelector('[path="name"]');
cell = getContainerCell(grid.$.items, 0, columns.indexOf(column));
cell.focus();
await sendKeys({ down: 'a' });
ugur-vaadin marked this conversation as resolved.
Show resolved Hide resolved
await sendKeys({ down: 'b' });
await sendKeys({ down: 'Enter' });
expect(cell._content.textContent).to.equal('ab');
});
});
});
Loading