Skip to content

Implement a11y-no-visually-hidden-interactive-elements linter rule#1671

Open
joelhawksley wants to merge 2 commits intomarcoroth:mainfrom
joelhawksley:1225
Open

Implement a11y-no-visually-hidden-interactive-elements linter rule#1671
joelhawksley wants to merge 2 commits intomarcoroth:mainfrom
joelhawksley:1225

Conversation

@joelhawksley
Copy link
Copy Markdown
Contributor

Implements the a11y-no-visually-hidden-interactive-elements rule from erblint-github's NoVisuallyHiddenInteractiveElements.

This rule flags interactive elements (a, button, summary, select, option, textarea) that have the sr-only CSS class, which visually hides them. Sighted keyboard users navigating to a visually hidden interactive element may become confused, thinking keyboard focus has been lost.

Note: input elements are intentionally not flagged to avoid false positives (e.g. file inputs).

Closes #1225

@github-actions github-actions Bot added documentation Improvements or additions to documentation linter typescript a11y linter-rule labels Apr 22, 2026
Implements the `a11y-no-visually-hidden-interactive-elements` rule from
erblint-github's `NoVisuallyHiddenInteractiveElements`.

This rule flags interactive elements (a, button, summary, select, option,
textarea) that have the `sr-only` CSS class, which visually hides them.
Sighted keyboard users navigating to a visually hidden interactive element
may become confused, thinking keyboard focus has been lost.

Note: `input` elements are intentionally not flagged to avoid false
positives (e.g. file inputs).

Closes marcoroth#1225
@brunoprietog
Copy link
Copy Markdown

Wouldn't this rule incorrectly flag things like sr-only focus:not-sr-only?

Avoid flagging interactive elements that use sr-only alongside
focus:not-sr-only or focus-within:not-sr-only, since these elements
become visible on focus (e.g. skip-to-content links).

Co-authored-by: Bruno Prieto <brunoprietog@users.noreply.github.com>
@joelhawksley
Copy link
Copy Markdown
Contributor Author

@brunoprietog that's a good point! The original rule from rubocop-github did not account for those patterns. I went ahead and added tests and a fix and put your name on the commit ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a11y documentation Improvements or additions to documentation linter linter-rule typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linter: Implement a11y-no-visually-hidden-interactive-elements rule

2 participants