-
-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Select] Controlled components should not change internal values when change handler is missing #1331
Comments
This makes sense, Radix's select does this (sandbox), and React will throw an error for controlled inputs that are missing the value change handler. Though I wonder in the Radix example when the value just doesn't change and there's no console warning/error, if it may be immediately obvious enough what is going on (in the context of a real project and not just a minimal example) Currently I think all our form controls do this in controlled mode (e.g. NumberField, Slider) What do you think? @michaldudak @atomiks @colmtuite |
Aren't there use cases for a controlled component where you want to change the value externally via |
IMO if a component is controlled, it should strictly behave like it. I can see a point in having imperative access to setting a value, though. Could we use the |
We decided that to make all "controllable" components match the React expectation:
|
Bug report
Current behavior
When a state variable is passed to the
value
prop of the Base UISelect
component, theSelect
menu can still be opened, and a different option can be selected without using theonValueChange
function. This behavior is unexpected for a controlled component since changes to its value should only occur through theonValueChange
handler.Expected behavior
The
Select
component should function as a controlled component. Changes to the selected value should only be possible when handled via theonValueChange
function. Thevalue
prop should strictly determine the displayed selected value.Reproducible example
Link to a CodeSandbox
Steps to reproduce:
value
prop of theSelect
component. (Already done)onValueChange
function. (Already commented out)Select
menu and try selecting a different option.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.The text was updated successfully, but these errors were encountered: