CheckboxGroup
A fieldset of Checkbox controls with one legend, hint and error.
Last updated
Show codeHide code
<CheckboxGroup legend="Notify me about" hint="Pick as many as you like.">
<Checkbox label="Comments" checked />
<Checkbox label="Mentions" />
<Checkbox label="Releases" />
</CheckboxGroup>For options that need a description, an icon or a price, see Choice card.
Add
npx @ava-ui/apogee add checkbox-group
Depends on utils. Use with checkbox.
Usage
---
import CheckboxGroup from '@/components/apogee/CheckboxGroup/CheckboxGroup.astro'
import Checkbox from '@/components/apogee/Checkbox/Checkbox.astro'
---
<CheckboxGroup legend="Size" direction="row">
<Checkbox label="S" />
<Checkbox label="M" />
<Checkbox label="L" />
</CheckboxGroup>
Anatomy
A <fieldset> with a <legend>, the controls in the default slot, and an
optional hint or error paragraph the fieldset is described by.
API
@composable. Any other native <fieldset> attribute (disabled, form) passes through.
| Prop | Type | Default | Description |
|---|---|---|---|
legend |
string |
— | Group label (required). |
hint |
string |
— | Helper text under the controls. |
error |
string |
— | Error text; replaces the hint, sets aria-invalid. |
direction |
'row' | 'column' |
'column' |
Lay the controls out in a row (wraps) or a column. |
id |
string |
auto | Fieldset id; hint/error ids derive from it. |
class |
string |
— | Extra classes on the fieldset, merged last. |
Variants
Show codeHide code
<CheckboxGroup legend="Column">…</CheckboxGroup>
<CheckboxGroup legend="Row" direction="row">…</CheckboxGroup>States
Show codeHide code
<CheckboxGroup legend="With hint" hint="Helper text.">…</CheckboxGroup>
<CheckboxGroup legend="With error" error="Pick at least one.">…</CheckboxGroup>
<CheckboxGroup legend="Disabled" disabled>…</CheckboxGroup>Error tint
The group’s error tints every control inside it; the children need no
hasError of their own.
Show codeHide code
<CheckboxGroup legend="Channels" error="Pick at least one">
<Checkbox label="Email" />
<Checkbox label="SMS" />
</CheckboxGroup>Examples
A parent checkbox in the mixed state over its children. Wire the parent to the children yourself; indeterminate only sets the first paint:
Show codeHide code
<CheckboxGroup legend="Notifications">
<Checkbox indeterminate label="All channels" />
<div class="ms-6 flex flex-col gap-2">
<Checkbox label="Email" checked />
<Checkbox label="Push" />
<Checkbox label="SMS" />
</div>
</CheckboxGroup>Accessibility
- Native
<fieldset>/<legend>: screen readers announce the legend with each control. - Hint and error are linked through
aria-describedby; the error hasrole="alert". - Pass
hasErrorto the controls that are wrong so they draw the critical border too.
Tokens
| Token | Used for |
|---|---|
--foreground-neutral |
Legend |
--foreground-neutral-faded |
Hint |
--foreground-critical |
Error |
Do / Don’t
- Do write the legend as the question or category (“Plan”, “Notify me about”).
- Do use
direction="row"for two or three short options only. - Don’t nest one group inside another.
Content
- Legend in sentence case, no trailing colon.
- Error text says what to do (“Pick at least one”), not what went wrong.