Skip to content

[combobox][select] Fix browser autofill with object values when autofill uses the label#4560

Merged
atomiks merged 4 commits intomui:masterfrom
mattrothenberg:fix/combobox-autofill-object-values
Apr 9, 2026
Merged

[combobox][select] Fix browser autofill with object values when autofill uses the label#4560
atomiks merged 4 commits intomui:masterfrom
mattrothenberg:fix/combobox-autofill-object-values

Conversation

@mattrothenberg
Copy link
Copy Markdown
Contributor

Summary

When using a Combobox with object values (e.g., { country: 'United States', code: 'US' }), browser autofill was not working because browsers send the displayed text (label) rather than the underlying value.

For example, when Chrome autofills a country field, it sends "United States" (the label displayed to the user), not "US" (the value). The existing autofill handler only matched against itemToStringValue, causing it to fail for object values where the label differs from the value.

Changes

  • Modified the autofill handler in AriaCombobox.tsx to first try matching by value, then fall back to matching by label
  • Added a test that verifies autofill works when the browser sends the label (e.g., "Canada") instead of the value (e.g., "CA")

Test Plan

The new test (should handle browser autofill with object values when autofill uses the label) was verified to:

  1. Fail without the fix (autofilled value not selected)
  2. Pass with the fix (correct item selected based on label match)

All existing tests continue to pass (6050 tests).

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 8, 2026

commit: 9f926e8

@mui-bot
Copy link
Copy Markdown

mui-bot commented Apr 8, 2026

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+82B(+0.02%) 🔺+15B(+0.01%)

Details of bundle changes


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

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 8, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 9f926e8
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69d71ab35171dd0008624672
😎 Deploy Preview https://deploy-preview-4560--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.

@mattrothenberg mattrothenberg force-pushed the fix/combobox-autofill-object-values branch from 1960e81 to 0f59f83 Compare April 8, 2026 14:23
@atomiks atomiks added type: bug It doesn't behave as expected. component: combobox Changes related to the combobox component. labels Apr 9, 2026
@atomiks atomiks added the component: select Changes related to the select component. label Apr 9, 2026
@atomiks atomiks changed the title [combobox] Fix browser autofill with object values when autofill uses the label [combobox][select] Fix browser autofill with object values when autofill uses the label Apr 9, 2026
Copy link
Copy Markdown
Contributor

@atomiks atomiks left a comment

Choose a reason for hiding this comment

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

Thanks for the fix @mattrothenberg

@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented Apr 9, 2026

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+82B(+0.02%) 🔺+16B(+0.01%)

Details of bundle changes


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

@atomiks atomiks merged commit 4733421 into mui:master Apr 9, 2026
23 checks passed
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: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants