Checkbox Group

Provides shared state to a series of checkboxes.

View as Markdown
Apples

Anatomy

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

Anatomy

API reference

defaultValue

string[]

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
string[] | undefined
value

string[]

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
string[] | undefined
onValueChange

function

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
allValues

string[]

Description

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

Type
string[] | undefined
disabled

boolean

false

Description

Whether the component should ignore user interaction.

Type
boolean | undefined
Default

false

className

string | function

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)
render

ReactElement | 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
| 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:

  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>

Nested parent checkbox

Form integration

To use checkbox group in a form:

  1. Pass the group’s name to <Field>
  2. Use the render prop to compose <Fieldset> and <CheckboxGroup>
  3. Use <Field.Item> to wrap each checkbox in the group
Using CheckboxGroup in a form
Extra toppings