Checkbox Group
Provides shared state to a series of checkboxes.
View as MarkdownAnatomy
Checkbox Group is composed together with Checkbox. Import the components and place them together:
import { Checkbox } from '@base-ui-components/react/checkbox';
import { CheckboxGroup } from '@base-ui-components/react/checkbox-group';
<CheckboxGroup>
<Checkbox.Root />
</CheckboxGroup>API reference
defaultValuestring[]
—
defaultValuestring[]
—- Name
- Description
Names of the checkboxes in the group that should be initially ticked.
To render a controlled checkbox group, use the
valueprop instead.- Type
string[] | undefined
valuestring[]
—
valuestring[]
—- Name
- Description
Names of the checkboxes in the group that should be ticked.
To render an uncontrolled checkbox group, use the
defaultValueprop instead.- Type
string[] | undefined
onValueChangefunction
—
onValueChangefunction
—- Name
- Description
Event handler called when a checkbox in the group is ticked or unticked. Provides the new value as an argument.
- Type
| (( value: string[], eventDetails: CheckboxGroupChangeEventDetails, ) => void) | undefined
allValuesstring[]
—
allValuesstring[]
—- Name
- Description
Names of all checkboxes in the group. Use this when creating a parent checkbox.
- Type
string[] | undefined
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: CheckboxGroup.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: CheckboxGroup.State, ) => ReactElement)
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
<CheckboxGroup>a controlled component - Pass an array of all the child checkbox values to the
allValuesprop on the<CheckboxGroup>component - Add the
parentboolean prop to the parent<Checkbox>
Nested parent checkbox
Form integration
To use checkbox group in a form:
- Pass the group’s
nameto<Field> - Use the
renderprop to compose<Fieldset>and<CheckboxGroup> - Use
<Field.Item>to wrap each checkbox in the group
<Form>
<Field.Root name="toppings">
<Fieldset.Root render={<CheckboxGroup />}>
<Fieldset.Legend>Toppings</Fieldset.Legend>
<Field.Item>
<Field.Label>
<Checkbox.Root value="anchovies" />
Anchovies
</Field.Label>
</Field.Item>
<Field.Item>
<Field.Label>
<Checkbox.Root value="olives" />
Olives
</Field.Label>
</Field.Item>
</Fieldset.Root>
</Field.Root>
</Form>