Skip to contents

Checkbox Group

Provides shared state to a series of checkboxes.

Apples

Usage guidelines

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:

  1. Bind the group's value with bind:value
  2. Pass an array of all the child checkbox values to the allValues prop on the <CheckboxGroup> component
  3. Add the parent boolean 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:value to share the array with the parent. undefined is an empty selection. Hold the array with eventDetails.cancel().

Type
string[]
Binding
bind:value
defaultValue string[] []
Description

The values an empty value starts from.

Type
string[]
Default
[]
allValues string[] —
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
Description

Whether the component should ignore user interaction.

Type
boolean | null
Default
false
onValueChange function —
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>. Spread props onto 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. null means 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
data-disabled
Present when the checkbox group is disabled.