Skip to contents

Checkbox Group

Provides shared state to a series of checkboxes.

View as Markdown
Apples

Usage guidelines

Anatomy

Checkbox Group is composed together with Checkbox. Import the components and place them together:

Anatomy

Examples

Labeling a checkbox group

Label the group with aria-labelledby and a sibling label element:

Using aria-labelledby to label a checkbox group

An enclosing <label> is the simplest labeling pattern for each checkbox:

Using an enclosing label to label a 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 (htmlFor/id).

Sibling label pattern with a native button

Native buttons with wrapping labels are supported by using the render callback to avoid invalid HTML, so the hidden input is placed outside the label:

Render callback

Form integration

Use Field and Fieldset for group labeling and form integration:

Using Checkbox Group in a form

Parent checkbox

A checkbox that controls other checkboxes within a <CheckboxGroup> can be created:

  1. Make <CheckboxGroup> a controlled component
  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

defaultValuestring[]
Description

Names of the checkboxes in the group that should be initially ticked.

To render a controlled checkbox group, use the value prop instead.

Type
valuestring[]
Name
Description

Names of the checkboxes in the group that should be ticked.

To render an uncontrolled checkbox group, use the defaultValue prop instead.

Type
onValueChangefunction
Description

Event handler called when a checkbox in the group is ticked or unticked. Provides the new value as an argument.

Type
allValuesstring[]
Description

Names of all checkboxes in the group. Use this when creating a parent checkbox.

Type
disabledbooleanfalse
Description

Whether the component should ignore user interaction.

Type
Default
false
classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function
Name
Type
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 ReactElement or a function that returns the element to render.

Type
data-disabled

Present when the checkbox group is disabled.

AttributeDescription
data-disabled

Present when the checkbox group is disabled.

CheckboxGroup.PropsHide

Re-Export of CheckboxGroup props as CheckboxGroupProps

CheckboxGroup.StateHide

CheckboxGroup.ChangeEventReasonHide

CheckboxGroup.ChangeEventDetailsHide