<Box display="grid" sx={{gap: 3}}><RadioGroup name="choiceGroup"><RadioGroup.Label>Choices</RadioGroup.Label><FormControl><Radio value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Radio value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Radio value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></RadioGroup></Box>
const WithOnChangeHandlers = () => {const [selectedRadioValue, setSelectedCheckboxValues] = React.useState('two')const [selectedRadioId, setSelectedRadioId] = React.useState()const handleRadioGroupChange = (selectedValue, e) => {setSelectedCheckboxValues(selectedValue)setSelectedRadioId(e.currentTarget.id)}const handleChoiceOneChange = e => {alert('Choice one has its own handler')}return (<Box display="grid" sx={{gap: 1}}><RadioGroup name="choiceGroup" onChange={handleRadioGroupChange}><RadioGroup.Label>Choices</RadioGroup.Label><FormControl><Radio value="one" onChange={handleChoiceOneChange} /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Radio value="two" defaultChecked /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Radio value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></RadioGroup>{selectedRadioValue && <div>The selected radio value is {selectedRadioValue}</div>}{selectedRadioId && <div>The last selected radio ID is {selectedRadioId}</div>}</Box>)}render(<WithOnChangeHandlers />)
<RadioGroup disabled name="choiceGroup"><RadioGroup.Label>Choices</RadioGroup.Label><FormControl><Radio value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Radio value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Radio value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></RadioGroup>
<RadioGroup required name="choiceGroup"><RadioGroup.Label>Choices</RadioGroup.Label><FormControl><Radio value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Radio value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Radio value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></RadioGroup>
<RadioGroup name="choiceGroup"><RadioGroup.Label>Choices</RadioGroup.Label><FormControl><Radio value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Radio value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Radio value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl><RadioGroup.Validation variant="error">Your choices are wrong</RadioGroup.Validation></RadioGroup>
<RadioGroup name="choiceGroup"><RadioGroup.Label>Choices</RadioGroup.Label><RadioGroup.Caption>You can pick any of these choices</RadioGroup.Caption><FormControl><Radio value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Radio value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Radio value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></RadioGroup>
<RadioGroup name="choiceGroup"><RadioGroup.Label visuallyHidden>Choices</RadioGroup.Label><FormControl><Radio value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Radio value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Radio value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></RadioGroup>
<><Boxid="choiceHeading"borderBottomWidth="1px"borderBottomStyle="solid"borderBottomColor="border.default"pb={2}mb={3}fontSize={3}>Choices</Box><RadioGroup aria-labelledby="choiceHeading" name="choiceGroup"><FormControl><Radio value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Radio value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Radio value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></RadioGroup></>
Name | Type | Default | Description |
---|---|---|---|
aria-labelledby | string | Used when associating the input group with a label other than RadioGroup.Label | |
children Required | RadioGroup.Label | RadioGroup.Caption | RadioGroup.Validation | FormControl | ||
disabled | boolean | false | Whether the input group allows user input |
id | string | A generated string | The unique identifier for this input group. Used to associate the label, validation text, and caption text. You may want a custom ID to make it easier to select elements in integration tests. |
name Required | string | The name used to identify this group of radios | |
onChange | (selected: string | null, e?: ChangeEvent<HTMLInputElement>) => void | An onChange handler that gets called when the selection changes | |
required | boolean | false | If true, the user must make a selection before the owning form can be submitted |
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. |
A title for the set of choices. If a RadioGroup.Label
is not passed as a child, you must pass the external title's ID to the aria-describedby
prop on RadioGroup
Name | Type | Default | Description |
---|---|---|---|
visuallyHidden | boolean | false | If true, the fieldset legend will be visually hidden |
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. |
Name | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | The caption content | |
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. |
If the user's selection has been flagged during validation, RadioGroup.Validation
may be used to render contextual validation information to help the user complete their task
Name | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | The validation message | |
variant Required | 'error' | 'success' | 'warning' | Changes the visual style to match the validation status | |
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. |