Eslint-plugin-jsx-a11y: Potential bug for rule of anchor-has-content

Created on 22 Mar 2017  ·  9Comments  ·  Source: jsx-eslint/eslint-plugin-jsx-a11y

According to the description here,

Accessible means that it is not hidden using the aria-hidden prop

Code below should not be an error.

$ cat a.jsx 
'use strict';

var React;

function a() {
    return <a aria-hidden />;
}

However,

$ eslint a.jsx

/home/mondwan/Documents/codeTest/eslintRules/a.jsx
  6:12  error  Anchors must have content and the content must be accessible by a screen reader  jsx-a11y/anchor-has-content

✖ 1 problem (1 error, 0 warnings)

Version

$ eslint --version
v3.18.0
$ cat .eslint.json 
{
  "rules": {
    "jsx-a11y/anchor-has-content": [
      "error",
      {
        "components": [
          ""
        ]
      }
    ],
  },
  "parserOptions": {
    "ecmaVersion": 5,
  },
  "parser": "/usr/lib/node_modules/babel-eslint/index.js",
  "ecmaFeatures": {
    "jsx": true
  },
  "plugins": [
    "react",
    "import",
    "jsx-a11y"
  ]
}
question

Most helpful comment

Never mind. Then, I simply disable the rule. Thanks for the answer.

All 9 comments

"Accessible means that it is not hidden using the aria-hidden prop" - thus, it's not accessible, and an error, when it is hidden.

<a aria-hidden /> is synonymous with <a aria-hidden={true} />, which is hidden, and thus not accessible, and thus should be an error.

The rule isn't saying that it doesn't have to have content if it's hidden; it's saying that anchors always must both have content and be visible.

But what if I am doing this on purpose? For example, I really need a hidden
link some where and triggered​ a file download. No accessibility here.

How do I discard such warning? Currently, I need to disable this rule by
typing eslint ... : 0

You only want it hidden from assistive technology, or you want it hidden from everything? You could hide it with CSS or the hidden attribute.

@mondwan why would you want to trigger a file download when the user didn't explicitly click on a real link to request it?

I'd just make that two clicks - the button to prepare the content, and then the link for the user to download when needed.

Umm, why click twice if one is sufficient?

Back to the question, why accessibility is enforced even I have declared this is a hidden link?

One isn't sufficient. You need one for the download for it to be semantically correct.

imo because hidden links aren't accessible; that's the point.

Never mind. Then, I simply disable the rule. Thanks for the answer.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uknmr picture uknmr  ·  5Comments

markduan picture markduan  ·  5Comments

almadsen picture almadsen  ·  6Comments

Steve-O-Cassels picture Steve-O-Cassels  ·  5Comments

calinoracation picture calinoracation  ·  3Comments