Make sure selected option is focused when listbox is opened #1768
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes an unintended regression introduced by making options render only when the listbox is open.
We now make sure the
tabIndex
is0
for the selected option, which will makeuseArrowKeyNavigation
focus it the first time.This worked before because the options were kept in the DOM, preserving their previously set
tabIndex
, but now we render them "from scratch" every time it is opened.Before:
focus-option-broken-2024-11-05_14.01.59.mp4
After:
focus-option-fixed-2024-11-05_14.01.21.mp4
Testing steps
If you follow these steps in
main
branch, you'll notice the first option is always focused when the listbox is opened, regardless of which one is selected.