Skip to content

Commit

Permalink
fix: do not move focus when focused in on grid via clicking backport (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ugur-vaadin authored Apr 15, 2024
1 parent afba12a commit 830e9d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/vaadin-grid-keyboard-navigation-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,15 @@

if (rootTarget === this.$.table ||
rootTarget === this.$.focusexit) {
// The focus enters the top (bottom) of the grid, meaning that user has
// tabbed (shift-tabbed) into the grid. Move the focus to
// the first (the last) focusable.
this._predictFocusStepTarget(
rootTarget,
rootTarget === this.$.table ? 1 : -1
).focus();
if (!this._isMousedown) {
// The focus enters the top (bottom) of the grid, meaning that user has
// tabbed (shift-tabbed) into the grid. Move the focus to
// the first (the last) focusable.
this._predictFocusStepTarget(
rootTarget,
rootTarget === this.$.table ? 1 : -1
).focus();
}
this._setInteracting(false);
} else {
this._detectInteracting(e);
Expand Down
13 changes: 13 additions & 0 deletions test/keyboard-navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,19 @@
expect(grid.shadowRoot.activeElement).to.equal(tabbableElements[3]);
});

it('should not enter grid on table click', () => {
const tabbableElements = getTabbableElements(grid.shadowRoot);

// Click and focusin on table element
mouseDown(tabbableElements[0]);
const event = new CustomEvent('focusin', {bubbles: true, composed: true});
event.relatedTarget = focusable;
tabbableElements[0].dispatchEvent(event);

// Expect no focus on header cell
expect(grid.shadowRoot.activeElement).to.be.null;
});

it('should set native focus to header on header cell click', () => {
const tabbableElements = getTabbableElements(grid.shadowRoot);
focusFirstHeaderCell();
Expand Down

0 comments on commit 830e9d1

Please sign in to comment.