Skip to content

Commit 5e92422

Browse files
authored
fix: do not move focus when focused in on grid via clicking (#7323)
1 parent 1230085 commit 5e92422

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

packages/grid/src/vaadin-grid-keyboard-navigation-mixin.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,12 @@ export const KeyboardNavigationMixin = (superClass) =>
814814
const rootTarget = e.composedPath()[0];
815815

816816
if (rootTarget === this.$.table || rootTarget === this.$.focusexit) {
817-
// The focus enters the top (bottom) of the grid, meaning that user has
818-
// tabbed (shift-tabbed) into the grid. Move the focus to
819-
// the first (the last) focusable.
820-
this._predictFocusStepTarget(rootTarget, rootTarget === this.$.table ? 1 : -1).focus();
817+
if (!this._isMousedown) {
818+
// The focus enters the top (bottom) of the grid, meaning that user has
819+
// tabbed (shift-tabbed) into the grid. Move the focus to
820+
// the first (the last) focusable.
821+
this._predictFocusStepTarget(rootTarget, rootTarget === this.$.table ? 1 : -1).focus();
822+
}
821823
this._setInteracting(false);
822824
} else {
823825
this._detectInteracting(e);

packages/grid/test/keyboard-navigation.common.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,17 @@ describe('keyboard navigation', () => {
544544
expect(grid.shadowRoot.activeElement).to.equal(tabbableElements[3]);
545545
});
546546

547+
it('should not enter grid on table click', () => {
548+
const tabbableElements = getTabbableElements(grid.shadowRoot);
549+
550+
// Click and focusin on table element
551+
mouseDown(tabbableElements[0]);
552+
focusin(tabbableElements[0], focusable);
553+
554+
// Expect no focus on header cell
555+
expect(grid.shadowRoot.activeElement).to.be.null;
556+
});
557+
547558
it('should set native focus to header on header cell click', () => {
548559
const tabbableElements = getTabbableElements(grid.shadowRoot);
549560
focusFirstHeaderCell();

0 commit comments

Comments
 (0)