Skip to content

[combobox] Avoid clearing selected value if item is not present in items array#3824

Merged
atomiks merged 2 commits into
mui:masterfrom
atomiks:fix/combobox-remove-clear-selection
Jan 28, 2026
Merged

[combobox] Avoid clearing selected value if item is not present in items array#3824
atomiks merged 2 commits into
mui:masterfrom
atomiks:fix/combobox-remove-clear-selection

Conversation

@atomiks

@atomiks atomiks commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

This avoids surprises with value getting cleared (to null) when the selected item isn't present in items, particularly in async combobox implementations. Native <select>s retain the previous value in state when the <option> gets removed from the list, with the exception that it automatically selects a fallback value which is a bit confusing here

Fixes #3818
Fixes #3502

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

pkg-pr-new Bot commented Jan 22, 2026

Copy link
Copy Markdown

commit: 09cecbe

@mui-bot

mui-bot commented Jan 22, 2026

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react ▼-348B(-0.08%) ▼-134B(-0.10%)

Details of bundle changes


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

@netlify

netlify Bot commented Jan 22, 2026

Copy link
Copy Markdown

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 09cecbe
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6979fa2dc62e380008f6038b
😎 Deploy Preview https://deploy-preview-3824--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 marked this pull request as ready for review January 22, 2026 07:59
@greptile-apps

greptile-apps Bot commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR removes the automatic value reconciliation logic that was clearing selected values when the items array changed. The previous behavior was clearing controlled values to null (or filtering out items in multiple mode) when the selected item wasn't present in the items array, which caused issues for async combobox implementations and paginated data scenarios.

  • Removed 46 lines of reconciliation logic from AriaCombobox.tsx that was forcing value clearing
  • Updated test expectations to reflect values persisting when items change
  • Added new test case validating that controlled object values not in items array still display their labels correctly using itemToStringLabel
  • Removed two tests that were validating the old reconciliation behavior

The change aligns with native <select> behavior which retains the previous value when an <option> is removed. The stringifyAsLabel utility already handles displaying labels for values not in the items array by using itemToStringLabel or extracting labels from object structures, ensuring the input displays correctly even when the selected item isn't in the current items list.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change cleanly removes problematic reconciliation logic that was causing regressions. The implementation is well-supported by the existing stringifyAsLabel utility which handles values not in the items array. Comprehensive tests validate the new behavior, and the approach aligns with native HTML form control behavior.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/combobox/root/AriaCombobox.tsx Removed automatic value reconciliation logic that was clearing selected values when items changed, allowing controlled values to persist even when not in items array
packages/react/src/combobox/root/ComboboxRoot.test.tsx Removed tests for the old reconciliation behavior and added test for showing labels of controlled values not in items array, updated test expectations to match new behavior

@sarthakmalik0810 sarthakmalik0810 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for the quick fix @atomiks! Since this might have broken async Comboboxes, do you think the release for this fix could be expedited? Many thanks!

@atomiks

atomiks commented Jan 28, 2026

Copy link
Copy Markdown
Contributor Author

@sarthakmalik0810 async items when the selected value wasn't in the items list was already broken for uncontrolled comboboxes, the logic previously was just to sync controlled ones afaict

We're sticking to monthly releases except in critical cases, you can use 1.0.0 or the canary release in the meantime

@atomiks atomiks merged commit 30f0ca8 into mui:master Jan 28, 2026
23 checks passed
@atomiks atomiks deleted the fix/combobox-remove-clear-selection branch January 28, 2026 12:03
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: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[combobox] Value gets cleared when items change [combobox] Combobox.Input value reset on re-renders

4 participants