Skip to content

Commit f893105

Browse files
committed
fix: do not move focus when focused in on grid via clicking (#7323)
1 parent 050ead0 commit f893105

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

797797
if (rootTarget === this.$.table || rootTarget === this.$.focusexit) {
798-
// The focus enters the top (bottom) of the grid, meaning that user has
799-
// tabbed (shift-tabbed) into the grid. Move the focus to
800-
// the first (the last) focusable.
801-
this._predictFocusStepTarget(rootTarget, rootTarget === this.$.table ? 1 : -1).focus();
798+
if (!this._isMousedown) {
799+
// The focus enters the top (bottom) of the grid, meaning that user has
800+
// tabbed (shift-tabbed) into the grid. Move the focus to
801+
// the first (the last) focusable.
802+
this._predictFocusStepTarget(rootTarget, rootTarget === this.$.table ? 1 : -1).focus();
803+
}
802804
this._setInteracting(false);
803805
} else {
804806
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)