[RadioGroup] Unable to reset value in controlled mode
See original GitHub issueš Note, I originally started a discussion around which where it was suggested that this might be a bug.
Bug report
Current Behavior
When using the RadioGroup in controlled mode, it doesnāt seem possible to reset it (so that none of the items selected) without violating type rules. The component only allows a string or undefined as the value. Passing null seems to correctly reset the radio group, but isnāt an allowed value.
Expected behavior
Iād expect that itās possible to reset the value of the RadioGroup somehow. Either by passing undefined or allowing null.
Reproducible example
https://codesandbox.io/s/heuristic-brook-x77cul?file=/App.js
Suggested solution
If there are no downsides, it seems that the type here could simply be updated to allow null for the value prop.
Your environment
| Software | Name(s) | Version |
|---|---|---|
| Radix Package(s) | @radix-ui/react-radio-group | 1.0.0 |
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How can I control a RadioGroup from material-ui?
My problem is that the RadioGroups don't care about the value I give them, they seem to be working in uncontrolled mode. I...
Read more >Controlled Mode - KendoReact Docs & Demos - Telerik
To manage the checked state of the Radio buttons in a RadioGroup: Use its value property. Handle the onChange event. Pass the new...
Read more >RadioGroup - Android Developers
Checking one radio button that belongs to a radio group unchecks any previously checked radio button within the same group.
Read more >Radio - Chakra UI
function RadioExample() { const [value, setValue] = React.useState('1') return ( <RadioGroup onChange={setValue} value={value}> <Stack direction='row'>Ā ...
Read more >Radio Group | Retool Component Library
A group of radio buttons to select a single value. Radio Group can group radio buttons in one or more columns, or wrap...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yeah exactly thatās why I asked about the reset form case, because thatās definitely a thing (and something we donāt currently do, which is the issue I linked to).
Yeah thatās the difficult part with
undefinedbecause of the controlled/uncontrolled nature. We detect as ācontrolledā if thereās a value if the prop is defined. It might be thatnullis the only way forward. I havenāt looked at the problem yet, but I think itās a general issue we have with all those form components, given how ouruseControllableStateworks and the controlled/uncontrolled detection.At the very least, I think we need to make sure all form components reset their state when a form reset occurs.
Iāll keep the issue opened then @ckastbjerg, thanks for the further responses.
hmm, yeah thatās an interesting example.
in this case i think i agree. perhaps the WAI ARIA docs are trying to express that interacting with the radios themselves should not clear their value and so āresettingā from an external interaction would be fine but iām not sure how radix could enforce that via controlled api.
perhaps easier to just allow it as i am unable to find any supporting material on why they say radios should only be unchecked on page load.