Skip to content

CheckboxGroup

Manages a set of Checkbox children as a single multi-select value array; works controlled or uncontrolled.

  • stable
  • since v0.1.0
  • 1.1 kB
  • forms
  • input

Wrapper has role="group"; child Checkbox inputs keep their native role and labels.

Preview
Open
tsx
import { Checkbox, CheckboxGroup } from "@arshad-shah/cynosure-react";
<CheckboxGroup defaultValue={["en"]} aria-label="Languages">
<Checkbox value="en">English</Checkbox>
<Checkbox value="fr">French</Checkbox>
</CheckboxGroup>

Each child Checkbox must carry a value — the group’s value is the array of currently-checked values.

Drive selection from state via value + onChange. Individual checked / onCheckedChange props on the children are ignored once they’re inside a group.

Preview
Open
tsx

The group renders a plain wrapper — wrap children in any layout primitive (Stack for vertical, Inline for horizontal).

Preview
Open
tsx

Setting disabled on the group cascades to every child. Children can also be disabled individually.

Preview
Open
tsx

For a visible legend, wrap the group in <Fieldset>.

Preview
Open
tsx
PropTypeDefaultDescription
value
string[]
Controlled array of selected checkbox values.
defaultValue
string[]
Uncontrolled initial array of selected values.
onChange
((value: string[]) => void)
Fires with the next array on every toggle.
name
string
Shared submit name for every checkbox in the group. Individual `name` overrides take precedence.
disabled
boolean
Disables every checkbox in the group.
aria-label
string
A11y label for the group — resolves to `aria-label` on the wrapper.
  • Wrapper uses role="group" — pair with aria-label or a <Fieldset legend="…"> so the group has an accessible name.
  • Each child Checkbox keeps its native role="checkbox" and individual label, so screen-reader counting (“3 of 5”) works.
  • disabled on the group is propagated to every child, including their aria-disabled state.
  • Selection lives in a single value array — there is no separate checked to keep in sync per item.
  • Pass name so each checked item submits as a repeated form value inside a native <form>.
  • Combine with FormField + FormMessage to drive “pick at least one” validation messaging.
  • Keep value items primitive strings — they round-trip cleanly through URLs and FormData.