Display focus ring in select options only when focus is visible #1604
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 changes a bit how we display the focus ring in
SelectNext
options, by making it visible only when the focus itself is considered visible by the browser (:focus-visible
instead of:focus
), which happens when interacting with components with the keyboard.select-with-arrows-2024-07-05_12.24.26.mp4
On the other hand, for users using the mouse, the focus ring becomes a bit annoying when it's always visible, and it can even be mistaken as part of the selected items style. With the changes in this PR, the focus ring won't show when using the mouse.
select-with-mouse-2024-07-05_12.23.44.mp4
There's only and edge case (which was likely the motivation to use
focus:ring
instead offocus-visible-ring
), which is that, if you open the listbox by clicking the select, and then navigate through the options via arrow keys, it feels as if the first item is being skipped, as it is initially not showing a focus ring.select-edge-case-2024-07-05_12.25.17.mp4
However, I think this is an edge case (people using the keyboard will usually use it all the time), which does not justify the UI implications.
For reference, this is how it currently looks like in
main
branch, with the focus ring always visible:select-always-ring-2024-07-05_12.27.03.mp4