-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
Broken Radio if null passed #14696
Comments
@koutsenko You need to choose between the controlled and uncontrolled behavior. Check the warning in the console. |
Ok, but how can i declare controlled-way that no one value is selected? |
@oliviertassinari And i have no warnings in console. |
@koutsenko You can set an empty string. I can confirm that no warning is raised. |
@koutsenko This problem only surfaces now because of #13915. We used to not support the uncontrolled radio mode. The best path forward I can think of is to reproduce the React warnings: |
@oliviertassinari you knows better 👍 Now after all I think that (just Javascript, no library-related rules):
I agree that null must raise warning and can be issue solution. Btw, you said, "no value" must be represented by empty string. |
Oops.. No, seems it's all wrong:
So, "uncontrolled" means if values are undefined, e.g. not defined in React lifecycles. Maybe all that case is about "controlled" behaviour? |
@koutsenko Here is how React handles the controlled/uncontrolled logic: |
How do we handle ToggleButtonGroup or Select? |
@eps1lon I should have looked at that, great answer! The ToggleButtonGroup component can only be controlled. For the Select component, React seems to encourage
|
I would go with that option then (including the warning). I think it's important that devs familiar with react don't encounter different behavior. |
Does this mean that the RadioGroup should never be controlled? |
@manonthemat It shouldn't switch between an uncontrolled and controlled state. |
That's an incorrect use of radio buttons. Radio buttons should always have one value selected – a default, or that chosen by the user to override the default. If you need "none" as one of the selections, you should add it. If you're old enough to remember vintage radios (or TVs) with radio buttons, you could force them into an invalid state by gently pressing a button until it disengaged the selected button, but not hard enough to engage the pressed button's latch. The result? No channel tuned (static). Not very exciting, but that's effectively what you're asking for. |
@mbrookes I'm reopening. I think that we should work when people switch between uncontrolled and controlled behavior. |
No "Female" option will be chosen.
If value was set to null programmatically, then setting it to another (programmatically) not work.
The text was updated successfully, but these errors were encountered: