Valid ARIA Properties In JSX
ID |
javascript.jsx_aria_props_valid |
Severity |
high |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
JavaScript |
Tags |
accessibility, jsx, reliability |
Description
Reports an aria-* attribute on a JSX element whose name is not a WAI-ARIA state or property, or
whose value is not one that property accepts.
Rationale
Both halves fail the same way, and they fail silently. React passes an unrecognised aria-* name
straight through to the DOM, where the accessibility tree ignores it; a value outside the property’s
vocabulary is discarded just as quietly. Either way the element looks annotated in the source and is
unannotated to a screen reader, and neither the compiler nor the browser says a word.
<div aria-lable="Close" /> // FLAW - misspelt, the label is never announced
<div aria-hidden="yes" /> // FLAW - aria-hidden is a boolean, "yes" is not
<h2 aria-level="two">Title</h2> // FLAW - aria-level takes an integer
<div aria-label="Close" /> // OK
<h2 aria-level={2}>Title</h2> // OK
<div aria-hidden={isHidden} /> // OK - computed at runtime, not judged here
Only a statically readable value is judged: a string literal, a numeric, boolean or null literal in
braces, or JSX’s valueless shorthand, which renders as true. Values are matched
case-insensitively, as browsers read them. Free-string properties such as aria-label accept any
text, so only their name is ever in question.