Skip to content

a11y style reader: an element hidden only inside a width media query is shown at other widths, so its unnamed controls are reported unconfirmed instead of decided #988

Closed

Description

@nc9

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: 990px vs max-width: 989px leaves a sub-pixel gap that browsers treat differently). Range syntax (width >= 990px) and em/rem units 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 @media inside @media, @supports around @media, and @container. Anything that is not a plain width range (orientation, prefers-*, hover, print, height, resolution, container queries) must keep unknown, because "some viewport shows it" cannot be justified.
  • Other hiding. A decided hide outside the media query, a hidden attribute, 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, keep unknown.

How to report it: a trade-off to decide

The maintainers need to choose one of two options.

  1. 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.
  2. Keep it unconfirmed, with a distinct reason. For example: button-name-unconfirmed, reason hidden-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:none inside 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.02px idiom) 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/only forms the reader cannot evaluate, and any other undecidable hiding keep today's unknown / -unconfirmed.
  • The CHROMIUM invariant table in packages/rules/tests/static-hidden.test.ts gains 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 validate passes in docs/.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementrulessize: M

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions