Checkbox Group
Provides shared state to a series of checkboxes.
Apples
Anatomy
Checkbox Group is composed together with Checkbox. Import the components and place them together:
Anatomy
import { Checkbox } from '@base-ui-components/react/checkbox';
import { CheckboxGroup } from '@base-ui-components/react/checkbox-group';
<CheckboxGroup>
<Checkbox.Root />
</CheckboxGroup>API reference
| Prop | Type | Default | |
|---|---|---|---|
defaultValue |
|
| |
value |
|
| |
onValueChange |
|
| |
allValues |
|
| |
disabled |
|
| |
className |
|
| |
render |
|
|
| Attribute | Description | |
|---|---|---|
data-disabled | Present when the checkbox group is disabled. | |
Examples
Parent checkbox
A checkbox that controls other checkboxes within a CheckboxGroup can be created:
- Make
CheckboxGroupa controlled component - Pass an array of all the child checkbox
values to theCheckboxGroup’sallValuesprop - Add the
parentboolean prop to the parentCheckbox
Nested parent checkbox
Form integration
To use checkbox group in a form:
- Pass the group’s
nameto aField - Use
Field.Labelto label each checkbox - Use the
renderprop to render the field as aFieldsetin order to label the group
Using CheckboxGroup in a form
<Form>
<Field.Root name="toppings" render={<Fieldset.Root />}>
<Fieldset.Legend>Toppings</Fieldset.Legend>
<CheckboxGroup>
<Field.Label>
<Checkbox.Root value="anchovies" />
Anchovies
</Field.Label>
<Field.Label>
<Checkbox.Root value="olives" />
Olives
</Field.Label>
<CheckboxGroup>
</Field.Root>
</Form>