Skip to content

Commit

Permalink
fix: use position absolute for focus-exit to avoid scroll position ch…
Browse files Browse the repository at this point in the history
…anges
  • Loading branch information
tomivirkki committed Dec 11, 2024
1 parent 48a954b commit 2d723bb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export const SelectionMixin = (superClass) =>
} else {
this.removeAttribute('tabindex');
}
this.$.focusexit.hidden = !isFocusable || !this.contains(this.__getActiveElement());
this.$.focusexit.hidden = !isFocusable;
}

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

Expand Down
5 changes: 5 additions & 0 deletions packages/virtual-list/src/vaadin-virtual-list-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ export const virtualListStyles = css`
#items {
position: relative;
}
#focusexit {
position: absolute;
top: 0;
}
`;
7 changes: 7 additions & 0 deletions packages/virtual-list/test/virtual-list-selection.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,13 @@ describe('selection', () => {
await nextFrame();
expect(list.hasAttribute('navigating')).to.be.false;
});

it('should shift tab to an item from outside', async () => {
afterButton.focus();
await shiftTab();

expect(document.activeElement).to.equal(getRenderedItem(0));
});
});
});

Expand Down

0 comments on commit 2d723bb

Please sign in to comment.