jsx-eslint / eslint-plugin-jsx-a11y

Static AST checker for a11y rules on JSX elements.
MIT License
3.4k stars 637 forks source link

Alt-text rule does not account for aria-hidden #803

Open lenzls opened 3 years ago

lenzls commented 3 years ago

Hello,

the jsx-a11y/alt-text rule does complain about elements which are out of the accessibility tree.

In my example I'm having an embedded SVG image that is purely for aesthetics and should therefore be ignored by screenreaders and the like.

    <object
      type="image/svg+xml"
      data={something}
      aria-hidden="true"
    />

Even though I've specified aria-hidden="true", I still get a warning about the missing alt-text.

Would you agree, that the rule should ignore elements out of the accessibility tree?

If yes, I can supply a pull request.

ljharb commented 3 years ago

What about browsers that don’t understand aria, but do understand alt text?

lenzls commented 3 years ago

Good point.

Although, one could argue that if you use aria-hidden, then obviously your target browser is recent enough to support it.

Also, I don't see another way of hiding an <object> from the AST.

ljharb commented 3 years ago

I don't think that's obvious; aria is designed to gracefully degrade in older browsers.