Skip to content

[combobox] Add getValueFromItem prop#4097

Draft
atomiks wants to merge 1 commit intomui:masterfrom
atomiks:codex/combobox-get-value-from-item
Draft

[combobox] Add getValueFromItem prop#4097
atomiks wants to merge 1 commit intomui:masterfrom
atomiks:codex/combobox-get-value-from-item

Conversation

@atomiks
Copy link
Contributor

@atomiks atomiks commented Feb 16, 2026

Fixes #3865
Fixes #3951
Closes #3853

Smaller and more flexible alternative to #3954. This explicitly supports object items with primitive value.

<Combobox.Root> needs to know what is passed to <Combobox.Item item={...}> ahead of time regarding the shape of items. e.g. value could be a primitive string or number, or the whole item object. This new prop getValueFromItem lets it know explicitly.

This can't be inferred automatically except in two cases:

  • { value, label } is the shape of the items objects
  • defaultValue/value aren't null

getValueFromItem supports arbitrary object shapes and the initial null value.

<Combobox.Root> will error if getValueFromItem is missing an value/defaultValue don't match the shape of items:

// @ts-expect-error - primitive selected values with object items require `getValueFromItem`
<Combobox.Root items={objectItems} defaultValue="a" />;
// @ts-expect-error - primitive selected values with object items require `getValueFromItem`
<Combobox.Root items={objectItems} value="a" />;
// @ts-expect-error - primitive selected values with object items require `getValueFromItem`
<Combobox.Root items={numberObjectItems} defaultValue={1} />;
// @ts-expect-error - primitive selected values with object items require `getValueFromItem`
<Combobox.Root items={numberObjectItems} value={1} />;

This does require synchronizing <Combobox.Item value={...} and getValueFromItem together. I added a wrapper example in the spec file.

The getValueFromItem name is differentiated from the other mappers (itemToStringValue, itemToStringLabel) as those ones operate on item values, not item objects.

@atomiks atomiks added type: new feature Expand the scope of the product to solve a new problem. component: combobox Changes related to the combobox component. labels Feb 16, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 16, 2026

commit: 5dd5f3f

@mui-bot
Copy link

mui-bot commented Feb 16, 2026

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+682B(+0.15%) 🔺+341B(+0.23%)

Details of bundle changes


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

@netlify
Copy link

netlify bot commented Feb 16, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 5dd5f3f
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6992c2fc2741a60008e9e5bb
😎 Deploy Preview https://deploy-preview-4097--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@atomiks atomiks force-pushed the codex/combobox-get-value-from-item branch 5 times, most recently from ce4bf53 to d844dfe Compare February 16, 2026 05:24
@atomiks atomiks force-pushed the codex/combobox-get-value-from-item branch from d844dfe to 5dd5f3f Compare February 16, 2026 07: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. type: new feature Expand the scope of the product to solve a new problem.

Projects

None yet

2 participants