Repository navigation
Description
What happens today
The a11y style reader (packages/rules/src/shared/page-styles.ts) keeps every rule inside @media as "uncertain". So an element hidden only by a width media query answers unknown, and an unnamed control inside it is reported as <check>-unconfirmed ("may be hidden by a style"). The docs say so ("an at-rule around it ... makes the elements it could reach unconfirmed").
The most common case is a theme's mobile menu, hidden on wide screens:
@media screen and (min-width: 990px) { menu-drawer { display: none } }<menu-drawer><button type="button"></button></menu-drawer>On every viewport narrower than 990px the drawer is not hidden by this rule, so the unnamed button is in the accessibility tree there. That is a real failure for mobile users, but it is reported as unconfirmed.
Seen in cloud report 01M5EPTVW7DRWHZ5XBYK9KCJGD (engine v0.0.124 replay, 10 pages): all 27 unconfirmed rows were one menu-drawer button per page under this pattern. They came from button-name, aria-command-name and aria-labels's aria-buttons check, on 9 pages each.
Repro (rules package, v0.0.124, a11y/button-name):
<style> |
result |
|---|---|
| (none) | button-name: fail |
menu-drawer{display:none} |
pass (hidden, not reported) |
@media screen and (min-width: 990px){menu-drawer{display:none}} |
button-name-unconfirmed: warn |
@media (max-width: 989px){menu-drawer{display:block}} @media (min-width: 990px){menu-drawer{display:none}} |
button-name-unconfirmed: warn |
Proposal
When everything that could hide an element sits inside width-only media queries, and those queries do not cover every width, the element is shown at the remaining widths. Its unnamed controls are then a real failure at those widths and should be decided.
Care is needed for:
- Complementary ranges.
(min-width: 990px)plus(max-width: 989.98px), both hiding, cover every width, so the element is hidden everywhere: not a failure. Ranges are open or closed at the edges (min-width: 990pxvsmax-width: 989pxleaves a sub-pixel gap that browsers treat differently). Range syntax(width >= 990px)andem/remunits need the same treatment. - Nested and combined queries. Cases include
@media (min-width: A) and (max-width: B), comma lists ((max-width: A), (min-width: B)),not,only, nested@mediainside@media,@supportsaround@media, and@container. Anything that is not a plain width range (orientation,prefers-*,hover,print, height, resolution, container queries) must keepunknown, because "some viewport shows it" cannot be justified. - Other hiding. A decided hide outside the media query, a
hiddenattribute,aria-hidden, an external stylesheet that could hide it at the remaining widths, or an ancestor hidden by an undecidable rule all mean the element is not shown at those widths with certainty. In those cases, keepunknown.
How to report it: a trade-off to decide
The maintainers need to choose one of two options.
- Report it as a fail with a width qualifier. For example:
button-name: N button(s) without accessible names (at widths below 990px).- Gain: it surfaces a real mobile failure and counts toward the score like any other fail.
- Risk: if the width analysis is wrong, it creates a false fail. The qualifier text has to stay accurate for open and closed ranges.
- Keep it unconfirmed, with a distinct reason. For example:
button-name-unconfirmed, reasonhidden-only-at-some-widths, with a message saying it is shown below 990px.- Gain: no new false-fail risk, and the cause is distinguishable from undecidable CSS.
- Cost: a real mobile failure still does not count as a fail.
Out of scope, by design: "hide until JavaScript runs" classes (for example a <body> class hidden by .x { visibility:hidden } and removed by a script) on unrendered pages. A static reader cannot settle these, and a rendered crawl does.
Acceptance Criteria
- An element hidden only by
display:noneinside one width-only media query (min-width,max-width, or the range syntax), with no other hiding, is no longer reported as plain-unconfirmed. It follows whichever reporting option is chosen above, and the choice and its reason are recorded in the PR. - Two width queries whose hiding ranges together cover every width (including the
min-width: N/max-width: N - 0.02pxidiom) leave the element treated as hidden at all widths: no fail, no new unconfirmed reason. - Media features other than width (orientation,
prefers-*,hover,print, height, resolution),@container,not/onlyforms the reader cannot evaluate, and any other undecidable hiding keep today'sunknown/-unconfirmed. - The CHROMIUM invariant table in
packages/rules/tests/static-hidden.test.tsgains width-media cases, including complementary ranges. No case where Chromium hides the element at every width becomes a fail, and no case where Chromium shows it at some width answers "hidden". - The docs for the a11y naming rules ("What squirrel can see") describe the width-media behaviour and the chosen reporting, and still say that hide-until-JavaScript classes on unrendered pages stay unconfirmed and are settled by a rendered crawl;
make validatepasses indocs/.
Activity
feat(rules): hidden-only-at-some-widths reason for controls a width-o…
fix(rules): cap at-rule depth in the width-media reader, safe empty d…
feat(rules): width-media hidden controls get their own unconfirmed re…