<Box display="grid" sx={{gap: 3}}><CheckboxGroup><CheckboxGroup.Label>Choices</CheckboxGroup.Label><FormControl><Checkbox value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Checkbox value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Checkbox value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></CheckboxGroup></Box>
const WithOnChangeHandlers = () => {const [selectedCheckboxValues, setSelectedCheckboxValues] = React.useState(['one', 'two'])const [lastSelectedCheckboxValue, setLastSelectedCheckboxValue] = React.useState()const handleCheckboxGroupChange = (selectedValues, e) => {setSelectedCheckboxValues(selectedValues)setLastSelectedCheckboxValue(e.currentTarget.value)}const handleChoiceOneChange = e => {alert('Choice one has its own handler')}return (<Box display="grid" sx={{gap: 1}}><CheckboxGroup onChange={handleCheckboxGroupChange}><CheckboxGroup.Label>Choices</CheckboxGroup.Label><FormControl><Checkbox value="one" defaultChecked onChange={handleChoiceOneChange} /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Checkbox value="two" defaultChecked /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Checkbox value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></CheckboxGroup>{Boolean(selectedCheckboxValues.length) && (<div>The selected checkbox values are {selectedCheckboxValues.join(', ')}</div>)}{Boolean(lastSelectedCheckboxValue) && <div>The last affected checkbox value is {lastSelectedCheckboxValue}</div>}</Box>)}render(<WithOnChangeHandlers />)
<CheckboxGroup disabled><CheckboxGroup.Label>Choices</CheckboxGroup.Label><FormControl><Checkbox value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Checkbox value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Checkbox value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></CheckboxGroup>
<CheckboxGroup required><CheckboxGroup.Label>Choices</CheckboxGroup.Label><FormControl><Checkbox value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Checkbox value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Checkbox value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></CheckboxGroup>
<CheckboxGroup><CheckboxGroup.Label>Choices</CheckboxGroup.Label><FormControl><Checkbox value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Checkbox value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Checkbox value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl><CheckboxGroup.Validation variant="error">Your choices are wrong</CheckboxGroup.Validation></CheckboxGroup>
<CheckboxGroup><CheckboxGroup.Label>Choices</CheckboxGroup.Label><CheckboxGroup.Caption>You can pick any or all of these choices</CheckboxGroup.Caption><FormControl><Checkbox value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Checkbox value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Checkbox value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></CheckboxGroup>
<CheckboxGroup><CheckboxGroup.Label visuallyHidden>Choices</CheckboxGroup.Label><FormControl><Checkbox value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Checkbox value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Checkbox value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></CheckboxGroup>
<><Boxid="choiceHeading"borderBottomWidth="1px"borderBottomStyle="solid"borderBottomColor="border.default"pb={2}mb={3}fontSize={3}>Choices</Box><CheckboxGroup aria-labelledby="choiceHeading"><FormControl><Checkbox value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl><FormControl><Checkbox value="two" /><FormControl.Label>Choice two</FormControl.Label></FormControl><FormControl><Checkbox value="three" /><FormControl.Label>Choice three</FormControl.Label></FormControl></CheckboxGroup></>
| Name | Type | Default | Description |
|---|---|---|---|
| aria-labelledby | string | Used when associating the input group with a label other than CheckboxGroup.Label | |
| children Required | CheckboxGroup.Label | CheckboxGroup.Caption | CheckboxGroup.Validation | FormControl | ||
| disabled | boolean | false | Whether the input group allows user input |
| id | string | a generated string | <span> The unique identifier for this input group. Used to associate the label, validation text, and caption text. <br /> You may want a custom ID to make it easier to select elements in integration tests. </span> |
| onChange | (selected: string[], 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. |
| 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. |
| 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. |