Skip to content

Commit 2d723bb

Browse files
committed
fix: use position absolute for focus-exit to avoid scroll position changes
1 parent 48a954b commit 2d723bb

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

packages/virtual-list/src/vaadin-virtual-list-selection-mixin.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export const SelectionMixin = (superClass) =>
286286
} else {
287287
this.removeAttribute('tabindex');
288288
}
289-
this.$.focusexit.hidden = !isFocusable || !this.contains(this.__getActiveElement());
289+
this.$.focusexit.hidden = !isFocusable;
290290
}
291291

292292
/** @private */
@@ -352,10 +352,7 @@ export const SelectionMixin = (superClass) =>
352352
} else {
353353
// Focus the focus exit element when tabbing so the focus actually ends up on
354354
// the next element in the tab order after the virtual list instead of some focusable child on another row.
355-
// Focusing the focus exit element causes scroll top to get reset, so we need to save and restore it
356-
const scrollTop = this.scrollTop;
357355
this.$.focusexit.focus();
358-
this.scrollTop = scrollTop;
359356
}
360357
}
361358

packages/virtual-list/src/vaadin-virtual-list-styles.js

+5
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ export const virtualListStyles = css`
2525
#items {
2626
position: relative;
2727
}
28+
29+
#focusexit {
30+
position: absolute;
31+
top: 0;
32+
}
2833
`;

packages/virtual-list/test/virtual-list-selection.common.ts

+7
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,13 @@ describe('selection', () => {
642642
await nextFrame();
643643
expect(list.hasAttribute('navigating')).to.be.false;
644644
});
645+
646+
it('should shift tab to an item from outside', async () => {
647+
afterButton.focus();
648+
await shiftTab();
649+
650+
expect(document.activeElement).to.equal(getRenderedItem(0));
651+
});
645652
});
646653
});
647654

0 commit comments

Comments
 (0)