Checkbox Group
A set of checkboxes that share one value array, with an optional list style and option descriptions.
Usage
import { Checkbox } from '@epilot/spark-ui/checkbox'
import { CheckboxGroup } from '@epilot/spark-ui/checkbox-group'function Notifications() {
return (
<CheckboxGroup defaultValue={['invoice']} aria-label="Notifications">
<label className="flex items-center gap-3">
<Checkbox value="meter" />
<span>Meter reading reminder</span>
</label>
<label className="flex items-center gap-3">
<Checkbox value="invoice" />
<span>New invoice</span>
</label>
</CheckboxGroup>
)
}CheckboxGroup holds the checked values as a string[]: each Checkbox takes a
value, and the group reports the ticked ones through onValueChange. Props and
slots mirror Radio's RadioGroup.
Wrap the group in FieldSet, FieldLegend, FieldDescription and FieldError
to give it a shared label, hint and error. See
Selection groups for slot order and for choosing between
checkboxes, switches and radios.
Use CheckboxGroup when several options can be on at once and the form saves them
together. Use Switch Group when each option
applies immediately. Use RadioGroup when exactly one option is allowed.
Examples
List styles
Set listStyle to show the options as a list of SelectionItem rows: soft,
surface, outlined or ghost. The styles reuse the input chrome, so a list sits
next to Input and Select in a form. SelectionItem takes the Checkbox as
control, plus a label and an optional description.
Required with an error
Put indicator="required" on FieldSet to mark the legend. A FieldError inside the
set renders as an error callout above the options, turns the legend red and tints
the list.
API Reference
CheckboxGroup
This component wraps Base UI Checkbox Group.
It accepts value, defaultValue, onValueChange, allValues and disabled.
| Prop | Type | Default | Description |
|---|---|---|---|
listStyle | "soft" | "surface" | "outlined" | "ghost" | none | Shows the options as a styled list of SelectionItem rows. Without it the group is a plain stack. Ignores gap. |
styleVariant | "solid" | "soft" | "surface" | "outline" | solid | Style of each checkbox control. Independent of listStyle. |
color | "accent" | "neutral" | "danger" | accent | Re-colors each checkbox control. |
gap | number | 3 | --spark-layout-gap units between checkboxes. Ignored when listStyle is set. |
className | string | — | Merges with the base styles. |
SelectionItem
Extends <label> props, except children. See Selection groups.
| Prop | Type | Default | Description |
|---|---|---|---|
control | ReactElement | — | A Checkbox, Switch or Radio. Spark adds its label and description ids to any aria-labelledby and aria-describedby it already has, so skip your own aria-label. |
label | ReactNode | — | The option name. It becomes the control's accessible name. |
description | ReactNode | — | Text under the label. It becomes the control's accessible description. |
Accessibility
CheckboxGrouprendersrole="group". Inside aFieldSet, the<fieldset>and<legend>name the set; outside one, passaria-labeloraria-labelledbyto the group.- The
FieldSetannounces its error first, then its description, througharia-describedby. A group-levelFieldErrorkeepsrole="alert", so screen readers read it when it appears. indicator="required"adds a visible*hidden from assistive tech, plus visually hidden text ("required"). PassindicatorLabelonFieldSetto translate it.indicator="optional"shows the visible text "(optional)".SelectionItemnames each checkbox by itslabeland describes it by itsdescription, so a screen reader reads both without merging them.- Keyboard:
Tabmoves between checkboxes,Spacetoggles the focused one. - Do not rely on color alone for the error: the callout text states the problem.