Skip to content

Commit

Permalink
fix: do not move focus when focused in on grid via clicking (#7323) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ugur-vaadin authored Apr 15, 2024
1 parent 7f8c68f commit 981854f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/grid/src/vaadin-grid-keyboard-navigation-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,10 +795,12 @@ export const KeyboardNavigationMixin = (superClass) =>
const rootTarget = e.composedPath()[0];

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
11 changes: 11 additions & 0 deletions packages/grid/test/keyboard-navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,17 @@ describe('keyboard navigation', () => {
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]);
focusin(tabbableElements[0], focusable);

// 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 981854f

Please sign in to comment.