Skip to content

[combobox] Support primitive item values#4686

Draft
atomiks wants to merge 8 commits into
mui:masterfrom
atomiks:codex/select-combobox-derived-indices
Draft

[combobox] Support primitive item values#4686
atomiks wants to merge 8 commits into
mui:masterfrom
atomiks:codex/select-combobox-derived-indices

Conversation

@atomiks
Copy link
Copy Markdown
Contributor

@atomiks atomiks commented Apr 26, 2026

Partially addresses #3594.
Related to #4419.

This lets Combobox use primitive values with supported object items, such as items={[{ value: "banana", label: "Banana" }]} with defaultValue="banana" or <Combobox.Item value="banana" />.

The public API stays the same: Combobox infers primitive values from supported item shapes instead of adding an itemValue prop. Select is unchanged in this PR.

Changes

  • Support primitive Combobox values for { value, label } items.
  • Use inferred values for selection, highlight, scroll into view, typeahead, autofill, and labels.
  • Keep Combobox item values available while filtering, closing, using inline lists, or rendering without items.
  • Add Combobox tests for primitive values, custom equality, autofill, virtualized items, typeahead, and inline lists.

Notes

  • This only infers values for the supported { value, label } item shape.
  • Other object item shapes still need matching values or isItemEqualToValue.

@atomiks atomiks added component: select Changes related to the select 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. component: combobox Changes related to the combobox component. labels Apr 26, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 26, 2026

commit: 0fd9141

@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented Apr 26, 2026

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+1.42KB(+0.31%) 🔺+538B(+0.36%)

Details of bundle changes

Performance

Total duration: 1,222.22 ms -112.48 ms(-8.4%) | Renders: 50 (+0) | Paint: 1,831.45 ms -210.60 ms(-10.3%)

Test Duration Renders
Select open (500 options) 42.71 ms ▼-15.21 ms(-26.3%) 14 (+0)

11 tests within noise — details


Check out the code infra dashboard for more information about this PR.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 26, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 0fd9141
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a0705f377ecbe000851f4b9
😎 Deploy Preview https://deploy-preview-4686--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 force-pushed the codex/select-combobox-derived-indices branch 2 times, most recently from d334087 to 9ed7cc6 Compare April 27, 2026 03:23
@atomiks atomiks requested a review from Copilot April 27, 2026 04:27
Copy link
Copy Markdown

Copilot AI left a comment

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 refactors Select and Combobox to stop storing selectedIndex as synchronized store state and instead derive it from snapshot arrays of item values, enabling closed programmatic value updates without requiring item registration/mounting.

Changes:

  • Replace stored selectedIndex with derived selectors based on itemValues / allItemValues snapshots for Select and Combobox.
  • Remove programmatic value-change force-mounting behavior while keeping autofill/interaction paths working.
  • Update Combobox list navigation to use a derived selected item/index (avoiding ref reads during render), and add regression tests.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/react/src/select/store.ts Replace stored selectedIndex with derived selectedIndex computed from itemValues.
packages/react/src/select/root/SelectRoot.tsx Remove programmatic value-change force-mounting; add itemValues state and related behavior.
packages/react/src/select/root/SelectRoot.test.tsx Add regression test ensuring programmatic value changes don’t force-mount the popup.
packages/react/src/select/positioner/SelectPositioner.tsx Remove direct selectedIndex resets when clearing value (now derived).
packages/react/src/select/popup/SelectPopup.tsx Switch selected-index checks to derived selector usage.
packages/react/src/select/item/SelectItem.tsx Maintain itemValues snapshot updates on item mount/unmount; remove direct selectedIndex writes.
packages/react/src/combobox/store.ts Add itemValues/allItemValues snapshots and derive selectedIndex from them.
packages/react/src/combobox/root/ComboboxRoot.test.tsx Add regression tests for deriving/highlighting/scrolling selected item on first open without items.
packages/react/src/combobox/root/AriaCombobox.tsx Remove stored selectedIndex sync logic; maintain snapshots; adjust navigation behavior to use derived selection.
packages/react/src/combobox/item/ComboboxItem.tsx Populate and snapshot itemValues/allItemValues from registered items for derived selection/indexing.
packages/react/src/combobox/input/ComboboxInput.tsx Remove selectedIndex updates from setIndices calls (now derived).
packages/react/src/combobox/clear/ComboboxClear.tsx Remove selectedIndex updates from setIndices calls (now derived).
packages/react/src/combobox/chip/ComboboxChip.tsx Remove selectedIndex updates from setIndices calls (now derived).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/react/src/combobox/item/ComboboxItem.tsx Outdated
@atomiks atomiks force-pushed the codex/select-combobox-derived-indices branch 5 times, most recently from ccf437d to 95eaa94 Compare April 27, 2026 05:18
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Apr 28, 2026
@atomiks atomiks force-pushed the codex/select-combobox-derived-indices branch from 12fb84e to 45b7329 Compare May 5, 2026 06:09
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label May 5, 2026
@atomiks atomiks changed the title [combobox][select] Derive selected index from values [combobox][select] Support primitive item values May 5, 2026
@atomiks atomiks force-pushed the codex/select-combobox-derived-indices branch from 350c3c1 to 40141a1 Compare May 8, 2026 03:15
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label May 8, 2026
@atomiks atomiks force-pushed the codex/select-combobox-derived-indices branch from 40141a1 to 7c15adb Compare May 8, 2026 03:30
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label May 8, 2026
@atomiks atomiks force-pushed the codex/select-combobox-derived-indices branch 2 times, most recently from 1d14d93 to 7ca490a Compare May 8, 2026 03:56
@atomiks atomiks force-pushed the codex/select-combobox-derived-indices branch from 7ca490a to a76c344 Compare May 8, 2026 04:11
@atomiks atomiks changed the title [combobox][select] Support primitive item values [combobox] Support primitive item values May 8, 2026
@atomiks atomiks force-pushed the codex/select-combobox-derived-indices branch from e67fc87 to 95e96a6 Compare May 11, 2026 06:20
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label May 15, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label May 15, 2026
@atomiks atomiks force-pushed the codex/select-combobox-derived-indices branch 2 times, most recently from f8837df to a4c193a Compare May 15, 2026 07:57
@atomiks atomiks force-pushed the codex/select-combobox-derived-indices branch from a4c193a to 97938e3 Compare May 15, 2026 08:10
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. component: select Changes related to the select 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.

2 participants