Repository navigation
Description
Since #921, the a11y checks that skip hidden controls read the page's <style> blocks (packages/rules/src/shared/page-styles.ts). A :root block of custom properties makes every element on the page "unknown" for display and visibility. That happens when a property name or value mentions display, visibility or all, and the block also holds a (, /, * or a quote. As a result, every unnamed button, field and dialog on the page is reported as <check>-unconfirmed (warn) instead of <check> (fail).
The pattern is common. A WordPress theme.json with a typography preset named "Display" produces it, and so do design tokens such as --font-display next to a calc() or var().
Repro
<!doctype html><html lang="en"><head><title>t</title>
<style>:root { --font-display: swap; --gap: calc(1rem + 2px) }</style>
</head><body><main><button class="x"></button></main></body></html>- v0.0.117:
a11y/button-namefails. - main (566c7e8 + fix(rules): a11y hidden-control checks read decidable <style> rules #678 #921):
button-name-unconfirmedwarn.cascade()returns"unknown"for the button and for every ancestor up to<html>.
On a real site, a 20-page audit of github.blog (quick, offline) has a11y/button-name, a11y/aria-labels, a11y/aria-command-name and a11y/aria-hidden-focus on 20 pages. These go from fail to unconfirmed warn. The source is the WordPress global styles :root block: --wp--custom--typography--presets--6--name: Display; ... --font: var(--text-display-shorthand).
Cause
MENTIONS_HIDING(/display|visibility|\ball\b/i) matches inside custom property names and values (--font-display,name: Display).readDeclarationsreturns"unknown"for the whole body when it holds(,/,*or a quote, even though a custom property cannot setdisplayorvisibility.- The compound that
parseSelector(":root")returns has no tag, id, class or attribute. It is indexed under*, so it is uncertain for every element, though:rootonly matches<html>. - With the root unknown,
displayunknown carries to every descendant.
Related
A second, smaller case comes from the same change. A <style> rule that shows a control is applied even when the page also loads an external stylesheet. Example: <link rel="stylesheet" href="bootstrap.css"> (which has [hidden]{display:none!important}) plus <style>button{display:inline-flex}</style> and <button hidden>. In a browser the button stays hidden, but main now reports it as an unnamed button fail. v0.0.117 skipped it. Hiding from a <style> block is softened when an external sheet exists, but showing is not.
Acceptance Criteria
- A
<style>rule whose declarations are all custom properties (--name: value) no longer makes any element'sdisplayorvisibilityunknown, whatever their names and values hold. -
:root(andhtml) as a subject applies to the<html>element only, not to every element. - With the repro above,
a11y/button-namereportsbutton-namefail, notbutton-name-unconfirmed. - A 20-page audit of github.blog no longer reports the site's unnamed controls as unconfirmed only because of its
:rootglobal styles. Controls really hidden by an unsettled rule may still be unconfirmed. - A
<style>rule that would show a control hidden by thehiddenattribute, a closed<dialog>or apopoverdoes not turn a skip into a fail when the page also loads an external stylesheet. It is unconfirmed instead. - Regression tests cover the custom-property
:rootblock, a WordPress-style presets block, and the external-stylesheet[hidden]case.
Activity
fix(rules): design tokens no longer make every control unconfirmed; a…
fix(rules): a11y reader handles :root custom properties and hidden in…