Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

react-a11y-anchors: false positive for hidden content #891

Closed
isellsoap opened this issue Oct 22, 2019 · 3 comments
Closed

react-a11y-anchors: false positive for hidden content #891

isellsoap opened this issue Oct 22, 2019 · 3 comments

Comments

@isellsoap
Copy link

Bug Report

  • tslint-microsoft-contrib version: 6.2.0
  • TSLint version: 5.20.0
  • TypeScript version: 3.6.4
  • Running TSLint via: CLI

TypeScript code being linted

/* … beginning of component definition, not important for this issue … */
const altText = 'Share with Facebook'

return (
  <a href={shareUrl} title={altText} target="_blank" rel="noopener noreferrer" {...props}>
    <svg
      aria-hidden
      xmlns="http://www.w3.org/2000/svg"
      viewBox="0 0 9 18"
    >
      <path d="M8.4 5.9H5.58V4.33c0-.8.09-1.24 1.25-1.24h1.55V0H5.9C2.9 0 1.86 1.5 1.86 4.03V5.9H0V9h1.86v9H5.6V9h2.48l.33-3.1z" />
    </svg>
    <VisuallyHidden>{altText}</VisuallyHidden>
  </a>
)
/* … ending component definition, not important for this issue … */

with tslint.json configuration:

{
  "defaultSeverity": "error",
  "extends": [
    "tslint:recommended",
    "tslint-react",
    "tslint-react-a11y", // <-- this is where tslint-microsoft-contrib is being referenced from
    "tslint-config-prettier",
    "tslint-react-hooks"
  ],
// other unimportant stuff to this issue …

Actual behavior

Linting error is being thrown with message

Link content can not be hidden for screen-readers by using aria-hidden attribute.

Expected behavior

As the link has an accessible text that screenreaders can access and read (via <VisuallyHidden>{altText}</VisuallyHidden>) I would expect that such an error shouldn’t occur.

@HamletDRC
Copy link
Member

Thank you for taking the time to submit such a well written bug report!

What exactly is VisuallyHidden?
Is it a reference to the ReachUI library?

@isellsoap
Copy link
Author

The answer to the second question is yes. :-) But VisuallyHidden is not necessary for the issue, the false positive also shows up when you write {altText} instead of <VisuallyHidden>{altText}</VisuallyHidden>.

@JoshuaKGoldberg
Copy link

💀 It's time! 💀

TSLint is deprecated and no longer accepting pull requests other than security fixes. See #876. ☠️
We recommend you instead use typescript-eslint to lint your TypeScript code with ESLint. ✅

👋 It was a pleasure open sourcing with you!

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

No branches or pull requests

3 participants