Skip to content

[combobox] Set initial highlight in inline combobox - #5230

Merged
atomiks merged 8 commits into
mui:masterfrom
atomiks:claude/vigorous-hawking-83ef7e
Jul 15, 2026
Merged

atomiks merged 8 commits into
mui:masterfrom
atomiks:claude/vigorous-hawking-83ef7e

Conversation

@atomiks

@atomiks atomiks commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

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 the items prop the selected index was never computed — items provided via items don'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

@atomiks atomiks added component: combobox Changes related to the combobox component. type: bug It doesn't behave as expected. labels Jul 14, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5230
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5230
    

commit: d157128

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+115B(+0.03%) 🔺+49B(+0.03%)

Details of bundle changes

Performance

Total 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.

@netlify

netlify Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit d157128
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a5759496ad00e0007400b39
😎 Deploy Preview https://deploy-preview-5230--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks atomiks added type: new feature Expand the scope of the product to solve a new problem. and removed type: bug It doesn't behave as expected. labels Jul 14, 2026 — with ChatGPT Codex Connector
@atomiks
atomiks marked this pull request as ready for review July 14, 2026 13:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 selectedIndex once 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.

@atomiks atomiks added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. and removed type: new feature Expand the scope of the product to solve a new problem. labels Jul 15, 2026
@atomiks
atomiks merged commit 3e9a252 into mui:master Jul 15, 2026
9 checks passed
@atomiks
atomiks deleted the claude/vigorous-hawking-83ef7e branch July 15, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: combobox Changes related to the combobox component. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[combobox] Set initial highlight in inline combobox

2 participants