Repository navigation
fix(a11y): accessible names for Checkbox and Switch - #1298
Draft
chad-agent wants to merge 7 commits into
Draft
chad-agent wants to merge 7 commits into
chad-agent wants to merge 7 commits into
Conversation
The row checkbox and the header select-all checkbox render a Checkbox without a label, so their accessible name was the string "undefined". Name them "Select row" and "Select all rows" (WCAG 2.2 SC 4.1.2). The mobile select-all checkbox keeps its visible label "Select All" as its name; a test guards it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each CheckboxMultiSelect item checkbox had no label, so Checkbox named it "undefined". It now points aria-labelledby at the option label text only, so the item icon stays out of the name, and the option description becomes its aria-describedby (APG Checkbox; WCAG 2.2 SC 4.1.2). This comes before the Checkbox change, which removes the "undefined" name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checkbox copied `label` into `aria-label`, which gave "[object Object]" for a JSX label and "undefined" for no label. The `<label for>` now names the control, and a consumer aria-label or aria-labelledby still wins. The check icon is hidden, so a checkbox with no label is not named "check" or "minus". The NoLabel story gets an aria-label (WCAG 2.2 SC 1.1.1, 4.1.2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Switch copied `label` into `aria-label`, which gave "[object Object]" for a JSX label and "undefined" for no label. The `<label for>` now names the control, and a consumer aria-label or aria-labelledby still wins. Adds Switch.test.tsx, which did not exist. The NoLabel story gets an aria-label (WCAG 2.2 SC 4.1.2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 6663b66 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
6 of 11 tasks
…eaking No component, prop, export or type changes, so app code keeps working. The changeset drops **Breaking:** and its migration list becomes "What to check after you upgrade". It also says that DOM snapshots with these controls change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Chromatic Storybook
Built from commit: Statuses as of the end of the run. The build link shows the live review state. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Screen readers now say the right name for checkboxes and switches.
TableandCheckboxMultiSelectget names too.Description
CheckboxandSwitchtake their name from<label for>. Before, a JSX label read "[object Object]". The check icon hasaria-hidden.Tablenames its row and select-all checkboxes "Select row" and "Select all rows". The mobile select-all keeps "Select All".CheckboxMultiSelectnames each item checkbox by its option label. The optiondescriptionbecomes the checkbox description.Links and tickets
Part of the split of #1189. Replaces #1295.
Good to know
CheckboxorSwitchwith no label goes from "undefined" to no name. The changeset says what to check after you upgrade.CheckboxMultiSelect.ItemDescriptionchild stays in the item name. "Select row" repeats on every row. I may rebase after fix(a11y): show a focus ring on Checkbox, Switch and RadioGroup #1291, chore(deps): bump vitest to 4.1.12 for @vitest/mocker advisories #1293 or feat(Table): maketable-layout: autothe default #683.Checklist
Not breaking: no prop, type or export changes. The changeset says what to check after you upgrade.
Contribution
buildandbuild-storybookwork locallyNot done: a manual check in Storybook. The only story change is an
aria-labelon the twoNoLabelstories.Accessibility
aria-labelNames is ticked for the controls in this PR only. Keyboard and Vision are not ticked because this PR does not change them, and I did not re-test them.
WCAG 2.2 criteria checked: 1.1.1 Non-text Content, 1.3.1 Info and Relationships, 2.5.3 Label in Name, 4.1.2 Name, Role, Value.
Tested:
getByRole(role, { name })). Each test for a fixed defect failed before its fix and passes after it. A few tests guard behavior that must not change: a consumeraria-labeloraria-labelledbystill wins, the mobile select-all keeps "Select All", and a labelled checked checkbox keeps its label.eslint-suppressions.jsondid not change.yarn test:visualcannot build its image locally right now, because Node 26 inmcr.microsoft.com/playwright:v1.64.1-nobleno longer ships corepack. So I ran the same specs in that image directly, withCI=true.node_modules, default rules, on the static Storybook build: all 58 stories of Checkbox, Switch, RadioGroup, CheckboxMultiSelect (menu open) and Link. This PR adds no violation compared withmain.Not tested:
<label for>on the Radix<button role="checkbox">(orswitch). HTML listsbuttonas labelable and Radix documents this pattern, but jsdom is the only engine I checked it in.Screenshots
No visual change. The visual tests above pass without new snapshots.
🤖 Generated with Claude Code