When to use it#
- Use it for one question where the user can choose none, one or several options: contact preferences, which services a notification covers, which documents are attached.
- Ask the question in the legend, and say how many answers are allowed above the options.
- Keep the list short. Past about 15 options, a search or another pattern is easier to use, such as a Combobox that takes several choices. Don’t use
<select multiple>. - Not for one yes or no answer, such as “I confirm the details are correct”: use a single Checkbox in a Field.
- Not for exactly one answer out of several: use a RadioGroup.
Example#
import { Checkbox, CheckboxGroup, Field } from '@kvirn-ui/react'
import { useCheckboxGroupTexts } from './texts.ts'
export function DefaultCheckboxGroup() {
const { texts } = useCheckboxGroupTexts()
return (
<CheckboxGroup.Root name="contact">
<CheckboxGroup.Legend>{texts.legend}</CheckboxGroup.Legend>
<CheckboxGroup.Prose>
<p>{texts.hint}</p>
</CheckboxGroup.Prose>
<CheckboxGroup.Option>
<Checkbox value="email" />
<Field.Label>{texts.email}</Field.Label>
</CheckboxGroup.Option>
<CheckboxGroup.Option>
<Checkbox value="text" />
<Field.Label>{texts.text}</Field.Label>
</CheckboxGroup.Option>
<CheckboxGroup.Option>
<Checkbox value="letter" />
<Field.Label>{texts.letter}</Field.Label>
</CheckboxGroup.Option>
</CheckboxGroup.Root>
)
}Use cases#
A plain form with no state
Without value the checkboxes are native and uncontrolled. Set which boxes start checked with defaultValue, and give the group a name. A form submit then sends every checked box under that name.
import { Button, Checkbox, CheckboxGroup, Field } from '@kvirn-ui/react'
import { useState } from 'react'
import { useCheckboxGroupTexts } from './texts.ts'
export function PlainFormCheckboxGroup() {
const { texts } = useCheckboxGroupTexts()
const [sent, setSent] = useState<string[] | undefined>(undefined)
return (
<form
onSubmit={(event) => {
event.preventDefault()
setSent(new FormData(event.currentTarget).getAll('contact').map(String))
}}
>
<CheckboxGroup.Root name="contact" defaultValue={['text']}>
<CheckboxGroup.Legend>{texts.legend}</CheckboxGroup.Legend>
<CheckboxGroup.Option>
<Checkbox value="email" />
<Field.Label>{texts.email}</Field.Label>
</CheckboxGroup.Option>
<CheckboxGroup.Option>
<Checkbox value="text" />
<Field.Label>{texts.text}</Field.Label>
</CheckboxGroup.Option>
<CheckboxGroup.Option>
<Checkbox value="letter" />
<Field.Label>{texts.letter}</Field.Label>
</CheckboxGroup.Option>
</CheckboxGroup.Root>
<Button type="submit" className="kv-button--primary">
{texts.send}
</Button>
{sent === undefined ? null : (
<p>
{texts.sent}: {sent.join(', ')}
</p>
)}
</form>
)
}Props in this example:
defaultValueon CheckboxGroup.Rootnameon CheckboxGroup.Root
Information: Did you know?
Read all the checked values with FormData.getAll("contact"). Every Checkbox in the group needs its own value.
Keep the choice in your form state
Your form library or reducer owns the values. Give the group the checked values and store the next ones it reports. The group never stores them, so if you don’t update value, the boxes stay as they were.
You chose: email
import { Checkbox, CheckboxGroup, Field } from '@kvirn-ui/react'
import { useState } from 'react'
import { useCheckboxGroupTexts } from './texts.ts'
export function ControlledCheckboxGroup() {
const { texts } = useCheckboxGroupTexts()
// This state stands in for your form library: the group only reports and renders.
const [contact, setContact] = useState<string[]>(['email'])
return (
<div>
<CheckboxGroup.Root name="contact" value={contact} onValueChange={setContact}>
<CheckboxGroup.Legend>{texts.legend}</CheckboxGroup.Legend>
<CheckboxGroup.Option>
<Checkbox value="email" />
<Field.Label>{texts.email}</Field.Label>
</CheckboxGroup.Option>
<CheckboxGroup.Option>
<Checkbox value="text" />
<Field.Label>{texts.text}</Field.Label>
</CheckboxGroup.Option>
<CheckboxGroup.Option>
<Checkbox value="letter" />
<Field.Label>{texts.letter}</Field.Label>
</CheckboxGroup.Option>
</CheckboxGroup.Root>
<p>
{texts.youChose}: {contact.length === 0 ? texts.nothing : contact.join(', ')}
</p>
</div>
)
}Props in this example:
valueon CheckboxGroup.RootonValueChangeon CheckboxGroup.Rootnameon CheckboxGroup.Root
Say what is wrong when nothing is chosen
Check the answer when the user sends the form. Set invalid and render a CheckboxGroup.ErrorMessage that says what to do. The error is read as part of the group’s description. required removes “(optional)” from the legend, but a group can’t be announced as required, so the text above the options must say it, as this example does.
import { Button, Checkbox, CheckboxGroup, Field } from '@kvirn-ui/react'
import { useEffect, useRef, useState } from 'react'
import { useCheckboxGroupTexts } from './texts.ts'
export function ErrorOnSubmitCheckboxGroup() {
const { texts } = useCheckboxGroupTexts()
const [contact, setContact] = useState<string[]>([])
const [attempts, setAttempts] = useState(0)
const formRef = useRef<HTMLFormElement>(null)
const isInvalid = attempts > 0 && contact.length === 0
// The group never moves focus: after a failed submit, you move it to the first box.
useEffect(() => {
if (attempts > 0) {
formRef.current?.querySelector('input')?.focus()
}
}, [attempts])
return (
<form
ref={formRef}
noValidate
onSubmit={(event) => {
event.preventDefault()
if (contact.length === 0) {
setAttempts((count) => count + 1)
}
}}
>
<CheckboxGroup.Root
name="contact"
required
invalid={isInvalid}
value={contact}
onValueChange={setContact}
>
<CheckboxGroup.Legend>{texts.legend}</CheckboxGroup.Legend>
<CheckboxGroup.Prose>
<p>{texts.requiredHint}</p>
</CheckboxGroup.Prose>
<CheckboxGroup.Option>
<Checkbox value="email" />
<Field.Label>{texts.email}</Field.Label>
</CheckboxGroup.Option>
<CheckboxGroup.Option>
<Checkbox value="text" />
<Field.Label>{texts.text}</Field.Label>
</CheckboxGroup.Option>
<CheckboxGroup.Option>
<Checkbox value="letter" />
<Field.Label>{texts.letter}</Field.Label>
</CheckboxGroup.Option>
<CheckboxGroup.ErrorMessage>{texts.errorMissing}</CheckboxGroup.ErrorMessage>
</CheckboxGroup.Root>
<Button type="submit" className="kv-button--primary">
{texts.send}
</Button>
</form>
)
}Props in this example:
Warning: Don't forget
The group never moves focus. After a failed submit, move it to the first checkbox or to an ErrorSummary. The error is read only when focus enters the group, so without the move a screen reader user isn’t told what went wrong (3.3.1 Error Identification).
Explain one option
A short text about one option goes in that option’s CheckboxGroup.Option as a Field.HelpText, directly under its label, and is read with that checkbox. Text about the whole group goes in CheckboxGroup.HelpText under the options. A description to read before answering goes in CheckboxGroup.Prose above them.
import { Checkbox, CheckboxGroup, Field } from '@kvirn-ui/react'
import { useCheckboxGroupTexts } from './texts.ts'
export function OptionHelpTextCheckboxGroup() {
const { texts } = useCheckboxGroupTexts()
return (
<CheckboxGroup.Root name="contact" defaultValue={['email']}>
<CheckboxGroup.Legend>{texts.legend}</CheckboxGroup.Legend>
<CheckboxGroup.Option>
<Checkbox value="email" />
<Field.Label>{texts.email}</Field.Label>
<Field.HelpText>{texts.emailHelp}</Field.HelpText>
</CheckboxGroup.Option>
<CheckboxGroup.Option>
<Checkbox value="text" />
<Field.Label>{texts.text}</Field.Label>
</CheckboxGroup.Option>
<CheckboxGroup.Option>
<Checkbox value="letter" />
<Field.Label>{texts.letter}</Field.Label>
</CheckboxGroup.Option>
<CheckboxGroup.HelpText>{texts.groupHelp}</CheckboxGroup.HelpText>
</CheckboxGroup.Root>
)
}A group that can’t be changed now
Disabling the group disables every checkbox natively, so Tab skips them. A screen reader can still reach them when reading the page, and tells the user they can't be used (each screen reader words it differently). So say why in visible help text, with what the person can do.
import { Checkbox, CheckboxGroup, Field } from '@kvirn-ui/react'
import { useCheckboxGroupTexts } from './texts.ts'
export function DisabledCheckboxGroup() {
const { texts } = useCheckboxGroupTexts()
return (
<CheckboxGroup.Root name="contact" defaultValue={['letter']} disabled>
<CheckboxGroup.Legend>{texts.disabledLegend}</CheckboxGroup.Legend>
<CheckboxGroup.Option>
<Checkbox value="text" />
<Field.Label>{texts.text}</Field.Label>
</CheckboxGroup.Option>
<CheckboxGroup.Option>
<Checkbox value="letter" />
<Field.Label>{texts.letter}</Field.Label>
</CheckboxGroup.Option>
<CheckboxGroup.HelpText>{texts.disabledHelp}</CheckboxGroup.HelpText>
</CheckboxGroup.Root>
)
}Props in this example:
disabledon CheckboxGroup.Root
Accessibility#
What it does for you#
- APG pattern: Checkbox, in a labelled group. The APG's checkbox examples group related boxes with
role="group"and a label; the native equivalent is<fieldset>and<legend>, which is what Root renders. There is no composite keyboard model: each checkbox is its own Tab stop. - Deviations: none from APG. Choices made: Fieldset wiring, option labels carry no optional marker, a group's
invaliddoesn't cascade, no form state. - Native elements used:
<fieldset>and<legend>(CheckboxGroup.RootandCheckboxGroup.Legend),<input type="checkbox">(Checkbox),<label for>(Field.Label).
A CheckboxGroup is one question with several answers that can all be true ("How do you want to be contacted?": email, text message, letter). CheckboxGroup.Root renders the <fieldset> and acts as a Fieldset.Root with group set, so CheckboxGroup.Legend, a description (CheckboxGroup.Prose), a help text (CheckboxGroup.HelpText) and CheckboxGroup.ErrorMessage work inside it. It holds no form state: the selected values are the value prop, and each change is reported up.
| Part | Element / role | ARIA / state | Notes |
|---|---|---|---|
| CheckboxGroup.Root | <fieldset> → group | As Fieldset: aria-describedby = descriptions, then the error. Native disabled. data-invalid, data-required, data-disabled. No aria-invalid and no aria-required (not supported on group) | Classes kv-checkbox-group kv-fieldset. Props: name, value, defaultValue, onValueChange(value, { reason: 'input', event }), invalid, required, disabled, messages, and every fieldset prop. The root is always a <fieldset> |
| CheckboxGroup.Legend | <legend>, the group's name | As on the Fieldset page | Ends with the optional marker ("(optional)" in English; other languages have their own word) in a group that isn't required: the marker belongs to the question |
| CheckboxGroup.Option | <div> with an <input type="checkbox"> and label | The option's name is its label. No "(optional)" on an option. The option's own help text (a Field.HelpText in its Option, outside the label) is in that checkbox's aria-describedby | An Option has class kv-option, no kv-field, no error message and marker="none"; disabled disables its checkbox. Field.Root around a checkbox still works. The checkbox gets the group's name and checked from value |
| Checkbox in a group | <input type="checkbox"> | data-invalid and data-disabled from the group, for styling. No aria-invalid: the group's error reaches users through the fieldset's aria-describedby | value is required on a Checkbox in a group; a dev warning fires when it's missing, or when checked or defaultChecked are given next to the group's (the group's wins). indeterminate and onCheckedChange still work on a Checkbox in a group. A "select all" box in the group is an option like the others: it needs a value, so its value is in the group's value while it is checked. A click calls the group's onValueChange first, with that value added or removed, then the box's own onCheckedChange (checkbox-group.test.tsx › a "select all" Checkbox in a group: onValueChange first, with its value added, then its own onCheckedChange). A box without a value warns and gets no name or state from the group (an uncontrolled group without a name still reads every checked box in the fieldset, so it reports such a box as "on"): put a select-all box outside the CheckboxGroup if its value shouldn't be in the group's |
useCheckboxGroup | the logic, for your own fieldset | returns name, groupRef, getCheckboxProps(value) | Options: name, value, defaultValue, onValueChange, invalid, disabled. Use it with useFieldset({ group: true }) and your own markup. Attach groupRef to your <fieldset> so an uncontrolled group can report its next value |
Rules, tested in checkbox-group.test.tsx:
- The group is named by its legend and described by its help text and error (
checkbox-group.test.tsx › the group is named by its legend and described by its help text and error). The legend is the first child. - Controlled by
value. Withvalue={['email']}, the checkbox withvalue="email"is checked and the others aren't. A change callsonValueChangewith the next array: the currentvaluewith the value added at the end, or removed (checkbox-group.test.tsx › onValueChange reports the next array from the value prop). The group never stores it; if the parent doesn't updatevalue, the box stays as it was. - Uncontrolled without
value.defaultValuesets the initial boxes (defaultChecked), the browser keeps the state, and a form submit sends every checked box under the group'sname(FormData.getAll).onValueChangestill fires, with the checked values read from the group's own<fieldset>at that moment (checkbox-group.test.tsx › uncontrolled: defaultValue, the form submit and onValueChange). namegoes on every checkbox in the group. Anameon a Checkbox wins.invalidmarks the group's own parts (legend, help text, error:data-invalid) and every option input (data-invalid, styling only). It doesn't cascade to the Fields'invalid, and no checkbox getsaria-invalidfrom it (checkbox-group.test.tsx › invalid styles every option and sets no aria-invalid).requiredremoves the optional marker ("(optional)" in English; other languages have their own word) from the legend and setsdata-required. A group has noaria-required; see Known issues.disabledis nativefieldset[disabled]: every checkbox inside is disabled and leaves the Tab sequence (checkbox-group.test.tsx › disabled disables every checkbox natively).- No arrow-key model. The root attaches no key handler (
checkbox-group.test.tsx › Arrow keys do not move focus between checkboxes). Each checkbox is its own Tab stop, in DOM order (checkbox-group.test.tsx › Tab moves through every checkbox in DOM order).
It announces nothing.
What you need to do#
- A
CheckboxGroup.Legendthat asks the question, first in the Root. Say how many answers are allowed in aCheckboxGroup.Proseabove the options ("Select all that apply"): it is read before answering, so it is a description. Use aCheckboxGroup.HelpTextunder the options only for what helps while answering ("You can change your mind later under My pages"). Both are text: the accessible description is the text content, so keep them short and plain, with no link in a help text. A Prose or HelpText directly in the group, not inside an option, describes the group; a Prose that isn't a description goes outside the group. An option's help text is aField.HelpTextin the option'sCheckboxGroup.Option. It sits directly under the label and outside it, so it is not part of what you click (checkbox-group.test.tsx › an option help text is a Field.HelpText in that CheckboxGroup.Option, outside its label, and has no axe violations).CheckboxGroup.HelpTextis listed after the description and before the error (checkbox-group.test.tsx › CheckboxGroup.HelpText is the group’s help text: after the description, before the error). - A
CheckboxGroup.Optionwith a direct-childCheckboxand aField.Labelfor each option;valueon every Checkbox. - Keep the list short. About 15 options is the limit before a search or a different pattern is better. Never
<select multiple>. - Pass
valueandonValueChangefrom your form state, ordefaultValueandnamefor a plain<form>. - Set
invalidand render aCheckboxGroup.ErrorMessage, then move focus to the first checkbox of the group on submit (or to the error summary). - "None of the above" is an option the consumer adds and handles; the group has no exclusive option.
Warning: Don't forget
Start the group with a CheckboxGroup.Legend that asks the question. Without it, a screen reader user hears the options with no question to answer (1.3.1 Info and Relationships; 3.3.2 Labels or Instructions).
Visual and modes#
- As Fieldset and Checkbox (see their pages). The options are a small gap apart (smaller in the compact density), and the legend sits above the description.
- forced-colors behaviour: as Checkbox. The group has no border of its own.
- RTL: the boxes are at the inline start, the right.
Focus management#
- Initial focus: not moved.
- Trap: no.
- Restore to: not applicable.
- On error: the group never moves focus. Move focus to the first checkbox of the group, or to an error summary.
- Never obscured by: nothing around the boxes clips the ring.
WCAG success criteria#
- 1.3.1 Info and Relationships (A): native fieldset and legend, the group's help text and error in its description.
- 3.3.1 Error Identification (A), 3.3.2 Labels or Instructions (A), 3.3.3 Error Suggestion (AA): the legend asks the question, the help text says how many, the error says what to do.
- 2.1.1 Keyboard (A), 2.4.3 Focus Order (A), 3.2.2 On Input (A): native keys, nothing moves focus when a box is checked.
- All the Checkbox criteria, for each option.
Keyboard#
- Focus
- native
- Selection follows focus
- n/a
- Arrows wrap
- n/a
- Shortcuts
- none
Checkboxes are independent, so each is its own Tab stop; the group is not a composite widget and arrow keys do nothing. The keys of one box are on the Checkbox page.
| Key | Where | What happens |
|---|---|---|
| Tab | before the group | Moves focus to the first checkbox. Each checkbox in the group is a Tab stop, in DOM order Test: checkbox-group.test.tsx › Tab moves through every checkbox in DOM order |
| Shift+Tab | on a checkbox | Moves focus to the previous checkbox, then out of the group Test: checkbox-group.test.tsx › Shift+Tab moves back through the checkboxes |
| Space | on a checkbox | Toggles that checkbox only, and reports the next value (native)Test: checkbox-group.test.tsx › Space toggles the focused checkbox and reports the next value |
| ArrowDown / ArrowUp / ArrowLeft / ArrowRight | on a checkbox | Nothing: focus and the checked boxes stay (native, not a composite) Test: checkbox-group.test.tsx › Arrow keys do not move focus between checkboxes |
| Tab | disabled group | Skips every checkbox of a disabled group (native fieldset[disabled])Test: checkbox-group.test.tsx › Tab skips the checkboxes of a disabled group (native) |
API reference#
import { Checkbox, CheckboxGroup, Field, useCheckboxGroup } from '@kvirn-ui/react'CheckboxGroup.Root
Renders <fieldset>, which a screen reader announces as a group. It is a Fieldset.Root with group set, takes every attribute of a <fieldset> and passes ref to it. Its options are CheckboxGroup.Option parts, each with a Checkbox and its label. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | – | The name every checkbox in the group submits under. A Checkbox’s own name wins. |
value | readonly string[] | – | Controlled: the values of the checked boxes, from your form state. The group never stores it. |
defaultValue | readonly string[] | – | Uncontrolled: the values checked at the start. The browser keeps the state after that. |
onValueChange | (value: string[], details: { reason: "input"; event }) => void | – | Called when a box changes. Controlled, it is value with the box’s value added at the end or removed. Uncontrolled, it is read from the checked boxes in DOM order. |
invalid | boolean | false | Marks the group and every checkbox with data-invalid, and shows the ErrorMessage. It sets no aria-invalid and does not make the Fields inside invalid. |
required | boolean | false | Sets data-required and removes the optional text from the legend. A group has no aria-required, so say what is required in the legend. |
disabled | boolean | false | Native fieldset disabled: every checkbox is disabled and skipped by Tab. Every checkbox also gets data-disabled. |
messages | Partial<KvirnMessages["field"]> | – | Overrides the legend’s optional text and the error prefix for this group. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-checkbox-group | always | The part class. It sits next to kv-fieldset. |
kv-fieldset | always | The fieldset class the default theme styles. |
data-invalid | present or absent | The group is invalid. Also on the legend, the help text, the error and every checkbox. |
data-required | present or absent | The group is required. Also on the legend. |
data-disabled | present or absent | The group is disabled. Also on every checkbox. |
aria-describedby | ids | Set for you: every description and help text in DOM order, then the error. Your own ids come after. |
CheckboxGroup.Option
Renders <div> (or <li>) around one answer: its checkbox, its Field.Label and its Field.HelpText. It has no “(optional)” marker and no error message of its own: those belong to the question.
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Disables this option’s control. Its label and help text get data-disabled. To disable every option, set disabled on the group. |
controlId | string | generated | The control’s id. Set it to link to the option from an error summary; the label, help text and control stay wired to it. |
as | "div" | "li" | "div" | The element to render. Use li when the options are a list, and then put the options in a <ul role="list"> inside the group, after the legend, so a screen reader announces the list. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-option | always | The part class. The default theme styles it. |
data-disabled | present or absent | The option is disabled. |
CheckboxGroup.Legend
Renders <legend>, the question and the group’s name. Put it first.
| Prop | Type | Default | Description |
|---|---|---|---|
marker | 'optional' | 'none' | 'optional' in a group that isn’t required, else 'none' | Whether the legend ends with the optional text, for example “(optional)”. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-fieldset-legend | always | The part class. |
data-invalid | present or absent | The group is invalid. |
data-required | present or absent | The group is required. |
data-disabled | present or absent | The group is disabled. |
CheckboxGroup.Prose
Renders <div> with the class kv-prose: the description, read before answering, above the options. It is listed in the group’s aria-describedby.
| Class or attribute | Values | Meaning |
|---|---|---|
kv-prose | always | The part class. The default theme sets it at 16px. |
data-invalid | present or absent | The group is invalid. |
data-disabled | present or absent | The group is disabled. |
CheckboxGroup.HelpText
Renders <p>: a short instruction under the options. It is listed in the group’s aria-describedby. A help text for one option is a Field.HelpText in that option’s CheckboxGroup.Option.
| Class or attribute | Values | Meaning |
|---|---|---|
kv-field-help-text | always | The part class. The default theme sets it at 14px. |
data-invalid | present or absent | The group is invalid. |
data-disabled | present or absent | The group is disabled. |
CheckboxGroup.ErrorMessage
Renders <p> that starts with the error icon and the hidden prefix. It renders only while the group is invalid, is the last item in the group’s aria-describedby, and is not a live region. Render one per group.
| Class or attribute | Values | Meaning |
|---|---|---|
kv-field-error-message | always | The part class. |
data-invalid | always | It renders only while the group is invalid. |
data-disabled | present or absent | The group is disabled. |
useCheckboxGroup
Options
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | – | The name every checkbox in the group submits under. |
value | readonly string[] | – | Controlled: the values of the checked boxes. |
defaultValue | readonly string[] | – | Uncontrolled: the values checked at the start. |
onValueChange | (value: string[], details: { reason: "input"; event }) => void | – | Called with the next values when a box changes. It only reports. |
invalid | boolean | false | data-invalid on every box, for styling. No aria-invalid. |
disabled | boolean | false | data-disabled on every box. A <fieldset disabled> does the disabling. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | undefined | – | The name, as given. |
groupRef | RefCallback<HTMLFieldSetElement> | – | Attach it to your <fieldset>, so an uncontrolled group can read its checked boxes when it reports. |
getCheckboxProps | (value: string) => CheckboxGroupItemProps | – | Spread on the <input type="checkbox"> with this value: name, checked or defaultChecked, onChange and the data attributes. |
Strings
These are the default texts in @kvirn-ui/i18n.
For your whole app, pass messages to KvirnProvider. For one CheckboxGroup, pass its messages prop.
These are the Field strings, because the legend and the error use them.
field.optional
The legend’s marker when the group is not required.
| Language | Default text |
|---|---|
| Svenska | (valfritt) |
| Suomi | (vapaaehtoinen) |
| Norsk bokmål | (valgfritt) |
| Norsk nynorsk | (valfritt) |
| English | (optional) |
field.errorPrefix
Read before the error message, so it is not mistaken for help.
| Language | Default text |
|---|---|
| Svenska | Fel: |
| Suomi | Virhe: |
| Norsk bokmål | Feil: |
| Norsk nynorsk | Feil: |
| English | Error: |
Known issues#
- A required group isn't announced as required. A screen reader user is not told that an answer is needed.
aria-requiredisn't supported ongroup(ARIA 1.2), and KvirnUI choosesaria-requiredover nativerequired, so a required group has only two signs: no optional marker in its legend, anddata-requiredfor styling. Say that an answer is needed in text: in the legend, or in aCheckboxGroup.Prosebefore the options ("Select at least one"). Prefer the legend, because TalkBack may not read the group's description (3.3.2 Labels or Instructions (A), 1.3.1 Info and Relationships (A)). aria-describedbyon a<fieldset>isn't announced consistently by TalkBack. On TalkBack (Android's screen reader) the help text and the error may not be read when the user enters the group. See the Fieldset page.- Uncontrolled
onValueChangereads the DOM. It reads the checked boxes of the group's<fieldset>when a box changes.
Warning: Don't forget
A required group is not announced as required. Write that an answer is needed in the legend or in the text above the options (3.3.2 Labels or Instructions).
Testing#
The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.
| AT + browser + OS | Agent check | Human check | Result | Notes |
|---|---|---|---|---|
| Automated (re-runnable tests) | ||||
| axe, WCAG 2.2 A and AA, every story, 4 themes | pass | n/a | pass | checkbox-group.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | checkbox-group.test.tsx (axe and role, name and state): the group is named by its legend and described by its help text and error |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 5 rows, each names a test in checkbox-group.test.tsx |
| Focus order and management | pass | n/a | pass | checkbox-group.test.tsx: Tab moves through every checkbox in DOM order |
| Display modes (forced colours, 320px reflow, text spacing, reduced motion) | pass | n/a | pass | the four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI |
| Core (required for beta) | ||||
| NVDA + Chrome + Windows | pending | pending | pending | |
| VoiceOver + Safari + iOS | pending | pending | pending | |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | pending | pending | pending | |
| TalkBack + Chrome + Android | pending | pending | pending | |
| VoiceOver + Safari + macOS | pending | pending | pending |
What to check#
With a screen reader and the keyboard, try:
- Tab into the group: the legend and "group" are read, then the help text and the error.
- Each box is one Tab stop, in reading order. The arrow keys move nothing.
- Space changes only the focused box.
- On an invalid group the error is read when focus enters.