Repository navigation
[combobox][autocomplete] Add loopFocus prop - #3592
Conversation
commit: |
Bundle size report
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
I was curious, maybe it would break https://deploy-preview-3592--base-ui.netlify.app/react/components/combobox#creatable, but no, it still seems OK. |
6468650 to
ee09365
Compare
mnajdova
left a comment
There was a problem hiding this comment.
After looking back into this, we decided not to this. The ARIA spec indicates:
Down Arrow: Moves focus to and selects the next option. If focus is on the last option, either returns focus to the combobox or does nothing.
We decided to add a loopFocus option to optionally not move the focus, and keep the behaviour where arrow down on the last element focused the combobox.
88c4531 to
cf7dde2
Compare
cf7dde2 to
3bb4daa
Compare
loopFocus prop and data-item-highlighted style attribute to Input
3bb4daa to
04cd18a
Compare
| loopFocus: true, | ||
| allowEscape: !autoHighlightMode, | ||
| loopFocus, | ||
| allowEscape: loopFocus, |
There was a problem hiding this comment.
Why was this changed? How does escape gets effected whether the focus is looping or not?
There was a problem hiding this comment.
allowEscape (poor term from Floating UI) means focus can escape the list (aka return to the input) but this requires loopFocus to be true - just a limitation of the implementation. I noticed we should keep the !autoHighlightMode check as well to avoid breaking previous behavior.
There was a problem hiding this comment.
Keeping the previous behaviour makes sense 👌 . For some reason initially I thought this is related to the Escape key press, but now reading the code more carefully is related for allowing the focus to move outside of the list, maybe we should rename it to be more explicit, but we can do this outside of this PR.
There was a problem hiding this comment.
Btw, we were anyway throwing a warning here https://github.com/mui/base-ui/blob/master/packages/react/src/floating-ui-react/hooks/useListNavigation.ts#L283 if loopFocus was false, so this doesn't change the behaviour in any way 👌
6c0af7e to
59eb850
Compare
loopFocus prop and data-item-highlighted style attribute to InputloopFocus prop
b2862c1 to
b29e55e
Compare
Closes #3456
Adds
loopFocusprop (default:true) toCombobox+Autocomplete. The input is always included in the focus loop (per ARIA guidelines), but you can disable it optionally (and the input can't be / isn't part of the focus loop in that case).NB: A
data-highlightedstate attribute (for when theinputpart has virtual focus) will be added in a separate PR