Skip to content

a11y: a :where()/:is() compound such as Tailwind v4's [hidden]:where(...) preflight makes every control unconfirmed #951

Closed

Description

@nc9

The a11y hidden-control reader (packages/rules/src/shared/page-styles.ts, parseSelector) gives a selector with any functional pseudo-class other than :not() a null subject: :where(), :is(), :has() and :nth-child(). A null subject could match any element. That holds for a bare :where(.a, .b). It is too wide when the compound already holds a plain part that limits the match.

Tailwind v4's preflight is the common case: [hidden]:where(:not([hidden="until-found"])) { display: none !important }. That rule can only match an element with the hidden attribute, but the reader treats it as reaching every element. When a page inlines the preflight in a <style> block, every unnamed control on the page becomes <check>-unconfirmed (warn) instead of <check> (fail), including visible controls.

Repro

<!doctype html><html lang="en"><head><title>t</title>
<style>[hidden]:where(:not([hidden="until-found"])) { display: none !important }</style>
</head><body><main><button class="y"></button></main></body></html>

This is related to #940, which covers undecidable rules that can only show an element. This one hides, and #940's criteria keep a hiding rule "unknown" for the elements it could reach. The fix here is to narrow which elements it could reach.

Acceptance Criteria

  • A selector whose compound holds a plain part (tag, id, class or attribute test) besides a functional pseudo-class is indexed by that part, so it can only reach elements that have it. [hidden]:where(…) reaches elements with the hidden attribute only.
  • With the repro above, a11y/button-name reports button-name fail, not button-name-unconfirmed.
  • An element that does carry hidden, in the same page, is still skipped or unconfirmed as today.
  • A bare :where(.a) or :is(…) with no other plain part keeps reaching any element.
  • Regression tests cover the Tailwind v4 preflight rule.
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

    bugrulessize: S

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions