Skip to content

[6.x] Give Switch controls an accessible name - #15575

Open
jaygeorge wants to merge 1 commit into
6.xfrom
fix/15391-switch-accessible-name
Open

jaygeorge wants to merge 1 commit into
6.xfrom
fix/15391-switch-accessible-name

Conversation

@jaygeorge

Copy link
Copy Markdown
Contributor

Description of the Problem

ui/Switch renders a role="switch" button whose only child is a decorative thumb. It had no accessible name unless a call site passed aria-label, so screen readers announced “switch, on” with no indication of what was being toggled.

Most CP call sites omitted a name — including the entry published-state toggle. axe-core reported critical button-name violations across several screens. WCAG 2.1 SC 4.1.2.

What this PR Does

  • Adds a label prop on ui/Switch that sets aria-label
  • Keeps fallthrough aria-label / aria-labelledby working for addons; warns in development when none is provided
  • Passes real names at CP call sites (entry Published, sites, roles, conditions, validation, Bard/Replicator set enabled, Revealer, Scaffold, etc.)
  • Uses aria-labelledby for Revealer when a visible input_label exists so the accessible name matches what’s on screen
  • Documents the requirement in Storybook and adds unit coverage

Fixes #15391

How to Reproduce

  1. Open any entry for editing
  2. Inspect the Published toggle in the sidebar (before this PR)
  3. Expected: an aria-label or aria-labelledby. Actual: <button role="switch" aria-checked="…"> with no name

Same on /cp/sites (site enabled) and /cp/roles/create (super user).

The switch has no visible text, so nameless instances failed axe
button-name checks (including entry publish state). Add a label prop,
wire names at CP call sites, and keep aria-label fallthrough for addons.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thirteen Switch instances render with no accessible name, including entry publish state

1 participant