Checkbox
Selects any number of options, with checked, unchecked and indeterminate states.
import { Checkbox } from '@windmorph/react';Keyboard
| Key | Action |
|---|---|
| Tab | Moves focus to the checkbox, and on to the next element. |
| Space | Checks or unchecks it. |
Enter doesn't toggle a checkbox, as with a native one; in a form it submits the form.
Screen reader
- Role
checkbox: a visually hidden native<input type="checkbox">(React AriauseCheckbox), inside a<label>.- Accessible name
- Its label (
children), oraria-labeloraria-labelledbywithout one. One of the three is required. - States announced
- Checked, not checked, or mixed ("partially checked") with
indeterminate; disabled; required (aria-required, or the nativerequiredwithvalidationBehavior="native"); invalid (aria-invalid).
- The drawn box, check mark and dash are hidden from assistive tech; the native input carries the state, so forms and labels work as they do natively.
indeterminateonly changes what is shown and announced; the checked state underneath stays as it was until the user acts.
Focus
- A disabled checkbox can't be focused. A read-only one can, but can't be changed.
- Keyboard focus shows M3's focus indicator around the 40px control: a 3px
secondaryoutline 2px outside it, with the focus state layer. Pointer presses show no ring.
Touch target
- The 18px box sits in a 40px control with an invisible 48 × 48px touch target. The whole label is part of the target too, since the root is a
<label>. - With
density(or the theme's), the control loses 4px a step, to 28px at -3, and the 48 × 48px target stays, reaching past the control. M3 asks not to apply density by default: offer it as the reader's choice. Checkboxes you stack yourself need their rows 48px apart, top to top, so two targets never overlap: 8px between them at density 0 and 4px more a step (20px at -3;gap-[calc(8px-var(--md-sys-density,0)*4px)]), asRadioGroupspaces its options, or use aListof checkbox items.
Motion
Under reduced motion the check mark appears at once instead of drawing in, and the box fills with a fade only. The press ripple appears at full size without growing.
What you need to do
- Give every checkbox a visible label that says what checking it means.
- For a parent checkbox, set
indeterminatewhile some, but not all, of its children are checked, and update it and the children inonCheckedChange. - Put related checkboxes under a visible heading or in a
fieldsetwith alegend, so the group has a name. - Show an error message next to an
invalidcheckbox and link it witharia-describedby; the checkbox only shows the error colour.