Skip to content

Commit 830e9d1

Browse files
authored
fix: do not move focus when focused in on grid via clicking backport (#2243)
1 parent afba12a commit 830e9d1

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/vaadin-grid-keyboard-navigation-mixin.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,15 @@
499499

500500
if (rootTarget === this.$.table ||
501501
rootTarget === this.$.focusexit) {
502-
// The focus enters the top (bottom) of the grid, meaning that user has
503-
// tabbed (shift-tabbed) into the grid. Move the focus to
504-
// the first (the last) focusable.
505-
this._predictFocusStepTarget(
506-
rootTarget,
507-
rootTarget === this.$.table ? 1 : -1
508-
).focus();
502+
if (!this._isMousedown) {
503+
// The focus enters the top (bottom) of the grid, meaning that user has
504+
// tabbed (shift-tabbed) into the grid. Move the focus to
505+
// the first (the last) focusable.
506+
this._predictFocusStepTarget(
507+
rootTarget,
508+
rootTarget === this.$.table ? 1 : -1
509+
).focus();
510+
}
509511
this._setInteracting(false);
510512
} else {
511513
this._detectInteracting(e);

test/keyboard-navigation.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,19 @@
602602
expect(grid.shadowRoot.activeElement).to.equal(tabbableElements[3]);
603603
});
604604

605+
it('should not enter grid on table click', () => {
606+
const tabbableElements = getTabbableElements(grid.shadowRoot);
607+
608+
// Click and focusin on table element
609+
mouseDown(tabbableElements[0]);
610+
const event = new CustomEvent('focusin', {bubbles: true, composed: true});
611+
event.relatedTarget = focusable;
612+
tabbableElements[0].dispatchEvent(event);
613+
614+
// Expect no focus on header cell
615+
expect(grid.shadowRoot.activeElement).to.be.null;
616+
});
617+
605618
it('should set native focus to header on header cell click', () => {
606619
const tabbableElements = getTabbableElements(grid.shadowRoot);
607620
focusFirstHeaderCell();

0 commit comments

Comments
 (0)