Skip to content

Commit cf2d97d

Browse files
ugur-vaadinvaadin-bot
authored andcommitted
fix: do not move focus when focused in on grid via clicking (#7323)
1 parent 0ed023e commit cf2d97d

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
@@ -539,6 +539,17 @@ describe('keyboard navigation', () => {
539539
expect(grid.shadowRoot.activeElement).to.equal(tabbableElements[3]);
540540
});
541541

542+
it('should not enter grid on table click', () => {
543+
const tabbableElements = getTabbableElements(grid.shadowRoot);
544+
545+
// Click and focusin on table element
546+
mouseDown(tabbableElements[0]);
547+
focusin(tabbableElements[0], focusable);
548+
549+
// Expect no focus on header cell
550+
expect(grid.shadowRoot.activeElement).to.be.null;
551+
});
552+
542553
it('should set native focus to header on header cell click', () => {
543554
const tabbableElements = getTabbableElements(grid.shadowRoot);
544555
focusFirstHeaderCell();

0 commit comments

Comments
 (0)