Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anchor-has-content should skip aria-hidden/role=presentation #1211

Open
TheJaredWilcurt opened this issue Sep 6, 2024 · 0 comments
Open

Comments

@TheJaredWilcurt
Copy link

anchor-has-content

Anchors must have content and the content must be accessible by a screen reader

That makes sense for this:

<a href="#example">
  <div class="box"></div>
</a>

But if you are doing a purely presentational image with clickable zones and want screen readers to skip the section entirely, you can add role="presentation" and aria-hidden:

<a
  aria-hidden="true"
  href="#example"
  role="presentation"
  tabindex="-1"
>
  <div class="box"></div>
</a>

In this context, there is no need to add additional text inside the link, so the linter should pass.

Current workaround:

<a
  aria-hidden="true"
  href="#example"
  role="presentation"
  tabindex="-1"
>
  <div class="box">
    <span class="sr-only">Box example</span>
  </div>
</a>

This is pointless though, as the text exists for screen readers, but the screen reader will not ever see it.

Also the tabindex="-1" is important, as it takes the link out of keyboard navigation. Without this you could tab to the link, but the screenreader wouldn't be able to explain what just happened because you are in an aria-hidden element that it wants to skip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant