Skip to content

Commit 5778227

Browse files
committed
fix: do not move focus when focused in on grid via clicking (#7323)
1 parent 5ebe76e commit 5778227

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
@@ -800,10 +800,12 @@ export const KeyboardNavigationMixin = (superClass) =>
800800
const rootTarget = e.composedPath()[0];
801801

802802
if (rootTarget === this.$.table || rootTarget === this.$.focusexit) {
803-
// The focus enters the top (bottom) of the grid, meaning that user has
804-
// tabbed (shift-tabbed) into the grid. Move the focus to
805-
// the first (the last) focusable.
806-
this._predictFocusStepTarget(rootTarget, rootTarget === this.$.table ? 1 : -1).focus();
803+
if (!this._isMousedown) {
804+
// The focus enters the top (bottom) of the grid, meaning that user has
805+
// tabbed (shift-tabbed) into the grid. Move the focus to
806+
// the first (the last) focusable.
807+
this._predictFocusStepTarget(rootTarget, rootTarget === this.$.table ? 1 : -1).focus();
808+
}
807809
this._setInteracting(false);
808810
} else {
809811
this._detectInteracting(e);

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

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

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

0 commit comments

Comments
 (0)