Skip to content

Fix: <select size> list box should not select first option when value does not match#36184

Open
Zelys-DFKH wants to merge 1 commit intofacebook:mainfrom
Zelys-DFKH:fix-select-listbox-value-mismatch
Open

Fix: <select size> list box should not select first option when value does not match#36184
Zelys-DFKH wants to merge 1 commit intofacebook:mainfrom
Zelys-DFKH:fix-select-listbox-value-mismatch

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

Summary

When size > 1, a <select> renders as a list box. List boxes don't require a selection, so the browser leaves nothing highlighted when no option carries the selected attribute. Dropdowns (size=1 or no size) always show something, so the browser picks the first option automatically.

updateOptions in ReactDOMSelect.js has a fallback that selects the first non-disabled option when the controlled value doesn't match anything. That's fine for dropdowns, where it matches what the browser does anyway. For list boxes it's wrong: on every re-render, updateOptions fires against the live options, finds no match, and silently marks the first option as selected.

The fix skips the fallback when node.size > 1.

Fixes #24469

How did you test this change?

Added two tests to ReactDOMSelect-test.js:

  • A list box with size="2" and a non-matching value prop stays deselected after re-render. This was the broken case.
  • A list box with size="2" and a matching value still selects the right option.

All existing tests in ReactDOMSelect-test.js and ReactDOMServerIntegrationSelect-test.js pass.

…value does not match

When a <select> has size > 1 (a list box), no option should be selected
if the controlled value prop does not match any option value. The browser
leaves list boxes with no selection in this case; React was incorrectly
falling back to selecting the first non-disabled option on every update.

The fix is one line: the first-option fallback in updateOptions now only
runs when node.size <= 1 (a dropdown), leaving list boxes unselected as
the HTML spec requires.

Fixes facebook#24469
@meta-cla meta-cla bot added the CLA Signed label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: <select size value> with value not matching any option results in first option being selected

1 participant