BUGFIX: template-no-empty-headings — recognize boolean aria-hidden#8
Closed
BUGFIX: template-no-empty-headings — recognize boolean aria-hidden#8
Conversation
Before: isHidden only matched aria-hidden="true" as a string literal.
Boolean / valueless / empty / mustache forms (<h1 aria-hidden />,
<h1 aria-hidden="" />, <h1 aria-hidden={{true}} />) slipped past as
"not hidden", so empty headings in those forms were flagged as empty
even when the author had intentionally hidden them from AT.
Fix: extract isAriaHiddenTruthy(). Recognize:
- valueless attribute (HBS AST has value=null or empty-string TextNode)
- "true" string literal (preserved)
- "" empty string
- {{true}} boolean mustache literal
- {{"true"}} string mustache literal
Per HTML boolean-attribute semantics (and jsx-a11y/vue-a11y convention),
presence of aria-hidden without an explicit "false" value is treated as
truthy. The strict ARIA spec treats bare aria-hidden as "undefined"
rather than "true", but every major linter in the ecosystem (and most
screen readers) treats it as true.
Four new test cases covering each of the recognized forms.
🏎️ Benchmark Comparison
Full mitata output |
Owner
Author
|
Moved upstream to ember-cli#2717. See that PR for ongoing review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
<h1 aria-hidden />,<h1 aria-hidden="" />, and<h1 aria-hidden="true" />are all intended to hide the heading from assistive technology.isHiddencheck only matchedaria-hidden="true"as a string literal.aria-hiddenwere treated as visible — a false positive on<h1 aria-hidden />-style intentionally-hidden empty headings.Fix: extract
isAriaHiddenTruthy(); accept valueless, empty,"true",{{true}}, and{{"true"}}forms.Known limitation: the comparison is strict
=== 'true', so ASCII-case variants likearia-hidden="TRUE"/aria-hidden="True"are NOT treated as truthy. If desired, this can be addressed in a follow-up.Strictly, the ARIA 1.2 spec treats a bare
aria-hiddenattribute as "undefined" rather than "true". But every major linter treats it as truthy (see Prior art), matching real-world browser/AT behavior.Four new test cases covering each recognized form.
Prior art
heading-has-content<h1 aria-hidden />as hidden; valueless boolean attribute counts as truthy.heading-has-contentheading-hiddenaria-hiddenon a heading as its own a11y problem.Upstream
[email protected]has the same false positive.