Skip to content

[select] Controlled components should not change internal values when change handler is missing #1331

Open
@nizhnyk

Description

@nizhnyk

Bug report

Current behavior

When a state variable is passed to the value prop of the Base UI Select component, the Select menu can still be opened, and a different option can be selected without using the onValueChange function. This behavior is unexpected for a controlled component since changes to its value should only occur through the onValueChange handler.

Expected behavior

The Select component should function as a controlled component. Changes to the selected value should only be possible when handled via the onValueChange function. The value prop should strictly determine the displayed selected value.

Reproducible example

Link to a CodeSandbox

Steps to reproduce:

  1. Pass a state variable to the value prop of the Select component. (Already done)
  2. Do not handle the onValueChange function. (Already commented out)
  3. Open the Select menu and try selecting a different option.
  4. Notice that the selected value changes without using onValueChange.

Base UI version

v1.0.0-alpha.5

Which browser are you using?

Chrome, Safari

Which OS are you using?

Mac OS

Additional context

This behavior contradicts the expected behavior of controlled components. It might cause inconsistencies in state management when using Select in forms or other UI workflows.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions