Checkbox Group
Provides shared state to a series of checkboxes.
Usage guidelines
- Form controls must have an accessible name: It can be created using
<label>elements, or theFieldandFieldsetcomponents. See Labeling a checkbox group and the forms guide.
Anatomy
Checkbox Group is composed together with Checkbox. Import the components and place them together:
Examples
Labeling a checkbox group
Label the group with aria-labelledby and a sibling label element:
An enclosing <label> is the simplest labeling pattern for each checkbox:
Rendering as a native button
By default, <Checkbox.Root> renders a <span> element to support enclosing labels. Prefer rendering each checkbox as a native button when using sibling labels (for/id). Set nativeButton and render a <button> with the render snippet.
Native buttons with wrapping labels are supported by using the render snippet to avoid invalid HTML, so the hidden input is placed outside the label:
Form integration
Use Field and Fieldset for group labeling and form integration:
Parent checkbox
A checkbox that controls other checkboxes within a <CheckboxGroup> can be created:
- Bind the group's
valuewithbind:value - Pass an array of all the child checkbox values to the
allValuesprop on the<CheckboxGroup>component - Add the
parentboolean prop to the parent<Checkbox.Root>
The group controls the parent checkbox's indeterminate state when some, but not all, child checkboxes are checked.
Nested parent checkbox
API reference
CheckboxGroup
value string[] —
- Name
- Description
Values of the checkboxes in the group that are ticked. Use
bind:valueto share the array with the parent.undefinedis an empty selection. Hold the array witheventDetails.cancel().- Type
string[]- Binding
bind:value
defaultValue string[] []
- Name
- Description
The values an empty
valuestarts from.- Type
string[]- Default
[]
allValues string[] —
- Name
- Description
Values of every checkbox the parent checkbox controls. Set this to render a parent checkbox with
Checkbox.Root parent.- Type
string[]
disabled boolean | null false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | null- Default
false
onValueChange function —
- Name
- Description
Called before the value changes. Call
eventDetails.cancel()to veto it.- Type
(value: string[], eventDetails: CheckboxGroupChangeEventDetails) => void
render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: CheckboxGroupState, children: Snippet | undefined]> —
- Name
- Description
Replace the default
<div>. Spreadpropsonto the host element.- Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: CheckboxGroupState, children: Snippet | undefined]>
disabled boolean
- Name
disabled- Description
Whether the group should ignore user interaction.
- Type
boolean
touched boolean
- Name
touched- Description
Whether the field has been touched.
- Type
boolean
dirty boolean
- Name
dirty- Description
Whether the field value has changed from its initial value.
- Type
boolean
valid boolean | null
- Name
valid- Description
Whether the field is valid.
nullmeans validity is not known yet.- Type
boolean | null
filled boolean
- Name
filled- Description
Whether the field has a value.
- Type
boolean
focused boolean
- Name
focused- Description
Whether the field is focused.
- Type
boolean