Repository navigation
[combobox][autocomplete] Reset list scroll position on filter - #5231
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,094.74 ms -12.95 ms(-1.2%) | Renders: 78 (+0) | Paint: 1,676.90 ms -38.97 ms(-2.3%) 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 a UX bug in Base UI’s Combobox/Autocomplete filtering flow where the list could remain scrolled to a stale position after the query changes, potentially leaving the user looking at the middle of a fresh result set (and hiding the auto-highlighted first item).
Changes:
- Add a layout-effect-based scroll reset in
AriaComboboxthat runs on typed input changes and resets the nearest overflow scroll container (skipping virtualized lists). - Refactor
isScrollableintoisScrollableY/isScrollableXhelpers to support clearer axis-specific scroll checks. - Add browser-only tests for Combobox and Autocomplete covering scroll reset behavior and key edge cases (wrappers, clipping ancestors, reordering, inline mode behavior).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/react/src/utils/scrollable.ts | Splits scrollability detection into axis-specific helpers used by scroll-container discovery. |
| packages/react/src/combobox/root/AriaCombobox.tsx | Implements the scroll reset on typed query updates by locating and resetting the nearest vertical scroll container. |
| packages/react/src/combobox/root/ComboboxRoot.test.tsx | Adds browser-mode tests validating scroll reset behavior across several Combobox compositions. |
| packages/react/src/autocomplete/root/AutocompleteRoot.test.tsx | Adds browser-mode tests validating scroll reset and ensuring inline navigation doesn’t trigger resets in mode="both". |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c2091da to
02accdd
Compare
Closes #5204
When the input value changes and the list re-filters, the scroll position stayed where it was — the user could be left looking at the middle of a fresh result set (and with
autoHighlight, the highlighted first item scrolled out of view). Autocomplete, built on the same internals, had the same bug.On a typed-input change, the nearest list overflow container is now reset directly to the top. It is keyed on the typed-input signal rather than the input value, so inline autocompletion (
mode="both"/"inline") rewriting the input during arrow navigation does not reset the scroll. Resetting the container directly avoids scrolling a surrounding dialog or page and does not depend on stale composite registry order when retained items are reordered. Virtualized lists own their scroll element and are left untouched.Playground: https://stackblitz.com/edit/ouhpah4p?file=src%2FApp.tsx