I have a React (typescript) app where I want to show a radio group but cut into two columns like so:
To do so, I use two RadioGroup from @material-ui/core
that I wish to completely control so the user cannot select an option in each group. My problem is that the RadioGroups don't care about the value
I give them, they seem to be working in uncontrolled mode. I can even see that the value is OK in their props, in the React DevTools.
Here is how I did it:
<div>Organizational attributes</div>
<div>
<RadioGroup
value={selectedPivotAttribute && selectedPivotAttribute.id.toString()}
onChange={selectPivotAttribute}
>
{props.attributes.filter(attribute => attribute.isHierarchical).map(attribute => (
<FormControlLabel
label={attribute.name}
key={attribute.id}
value={attribute.id.toString()}
control={<Radio/>}
/>
))}
</RadioGroup>
</div>
<div>Secondary attributes</div>
<div>
<RadioGroup
value={selectedPivotAttribute && selectedPivotAttribute.id.toString()}
onChange={selectPivotAttribute}
>
{props.attributes.filter(attribute => !attribute.isHierarchical).map(attribute => (
<FormControlLabel
label={attribute.name}
key={attribute.id}
value={attribute.id.toString()}
control={<Radio/>}
/>
))}
</RadioGroup>
</div>
The two RadioGroups are correctly rendered and functional, they also trigger the onChange
handler, but they don't care about the value I give them, they just live their own life and thus they are not mutually exclusive.
I am trying to reproduce in a codesandbox but I can't even get one RadioGroup to work at all in there. Here it is anyway: https://codesandbox.io/s/gallant-cloud-yixdd. I can't think of anything simpler than that while remaining relevant to the case.