Repository navigation
[combobox] Set initial highlight in inline combobox - #5230
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,167.12 ms -43.09 ms(-3.6%) | Renders: 78 (+0) | Paint: 1,833.54 ms -51.33 ms(-2.7%) No significant changes — details 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. |
There was a problem hiding this comment.
Pull request overview
This PR fixes an inline Combobox edge case where an always-open inline combobox using the items prop would not initially highlight (or scroll to) the selected value, because it never entered a closed state where the selected index is normally computed.
Changes:
- Seed
selectedIndexonce at store creation for inline + initially open +items-prop comboboxes, using the initially filtered list. - Add browser-only tests covering initial highlight/scroll behavior and ensuring the seed does not “snap back” after later interactions or late-resolving selections.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/react/src/combobox/root/AriaCombobox.tsx | Seeds an initial selectedIndex for inline, initially-open items lists so the mount/open sync can highlight and scroll to the selection. |
| packages/react/src/combobox/root/ComboboxRoot.test.tsx | Adds coverage (browser env) for initial highlight/scroll and for non-regression scenarios around filtering, blur, multiple mode, virtualization, and late selection resolution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fixes #5226
A non-inline combobox highlights and scrolls to the selected value when the popup opens. An inline combobox (
<Combobox.Root inline open>) never passes through a closed state, so with theitemsprop the selected index was never computed — items provided viaitemsdon't self-register their index the way individually rendered<Combobox.Item>s do — and the selection was neither highlighted nor scrolled into view on the initial render.The selected index is now seeded once at store creation for inline
items-prop lists, resolved against the filtered list from the first render. List navigation's existing open-sync effect then applies the highlight and scrolls the selection into view on mount. Because the seed is computed only once by construction, typing to filter, blurring, toggling a selection in multiple mode, or a selection that resolves after mount can't snap the highlight back or scroll the list away.Works for both windowed and non-windowed lists — virtualized consumers receive the selected index through
onItemHighlighted.Demo: https://stackblitz.com/edit/l8cz3ewh-hygonjth