[test] Automate 2.4.7 Focus Visible - #48945
Conversation
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
Lets a fixture assert every axe rule it exercises rather than only the CSS-dependent visual ones, which is what the per-component WCAG reports need.
Adds a table-driven Playwright suite covering 1.4.10 Reflow, 1.4.4 Resize Text and 1.4.12 Text Spacing across the assessed components. axe has no rule for any of them, so they were rated Manual on evidence from source review.
Adds `pnpm a11y:scorecard`, which parses the count table out of every `<Component>/accessibility.md`, regenerates the index table, and emits the JSON that the public conformance page is built from. `--check` fails when either output is stale so a new report cannot land without its rollup.
Compares each control focused and unfocused in a real browser. axe has no rule for this criterion, and the existing unit tests for it are skipped under jsdom, so it rested on source review alone. Drops the evidence flag on the six components that carried one. The rating stays Hybrid rather than Automated: the test proves an indicator exists, not that it has enough contrast, which is 1.4.11 and still manual.
da38130 to
fda28fb
Compare
PR reviewThe pixel-comparison approach is sound — Bugs (2)1. 🟡
|
Automates 2.4.7 Focus Visible across the seven components that rate it, by comparing each control focused and unfocused in a real browser.
axe has no rule for this criterion, and the unit tests that exist for it are
skipIf(isJsdom())— so they never actually run. It was rated on source review alone.Why a pixel comparison rather than a computed-style diff: MUI's focus indicator is usually the ripple, a child element that appears in the DOM. Diffing styles on the control itself would miss it entirely and report a false failure. The capture is padded by 8px so an outline painted outside the control's box still counts.
I mutation-tested the assertion rather than trusting a green run: stripping outlines, box-shadows and the ripple makes 4 of the 7 fail. The remaining three have additional real indicators the sabotage did not remove — TextField's notched-outline border colour, for instance.
The rating stays 🔁 Hybrid, not ⚙️ Automated. The test proves an indicator exists, not that it has enough contrast — that is 1.4.11, which is still manual. What changes is the evidence flag: six components drop their 🚩, taking verified coverage from 184/230 to 190/230.
Follow-up is 1.4.11 itself. A spike confirmed it can be measured without new dependencies by screenshotting an element, letting the browser decode it into a canvas, and sampling pixels — that reproduced the Switch thumb-vs-track ratio at 2.26:1, inside the 1.8–2.6:1 range measured by hand in the report.
Important
How to review this PR
Layer 13 of 14 in a stacked series (#48915 → #48926). Its branch is built on
a11y/stack/scorecard(#48925). GitHub cannot chain PR bases across a fork, so every PR in the series targetsmasterinstead.Review only the last commit —
fda28fb. Everything above it belongs to the layers below, and disappears as those merge.Part of the WCAG conformance effort (#14187).