no-redundant-roles
Configuration
Some HTML elements have native semantics that are implemented by the browser. This includes default/implicit ARIA roles. Setting an ARIA role that matches its default/implicit role is redundant since it is already set by the browser.
Rule Details
The rule fires on a JSX opening element when all of the following hold:
- The element name resolves (through
settings['jsx-a11y'].polymorphicPropNameandsettings['jsx-a11y'].components) to an HTML element that has an implicit ARIA role (<button>→button,<nav>→navigation,<img>→img, etc.). - The element carries an explicit
roleattribute whose statically-literal value (lower-cased) equals that implicit role. - The element is not in the allow-list for that tag (see Rule Options).
Non-literal role values (Identifiers, CallExpressions, template literals with substitutions, etc.) cannot be statically determined and never trigger the rule. The role attribute name is matched case-insensitively; the value is compared after .toLowerCase() so role="BUTTON" is the same as role="button".
Some HTML elements have a context-sensitive implicit role:
<a>/<area>/<link>— only acquire thelinkrole when anhrefattribute is present.<img>— has implicitimgUNLESSalt=""(decorative) or the literalsrcvalue contains.svg.<input>— the implicit role depends ontype:button/submit/reset/image→button,checkbox→checkbox,radio→radio,range→slider, anything else (or absent) →textbox.<select>—comboboxby default;listboxwhenmultipleis truthy orsize > 1.<menu>/<menuitem>— depend on the literaltypevalue.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Rule Options
The default options allow nav to carry an implicit navigation role, as is advised by W3C. Options are provided as an object keyed by HTML element name; the value is an array of implicit ARIA roles that are allowed on the specified element.
Specifying an entry for a key REPLACES the default for that key. To disable the built-in nav exception, set nav to an empty array:
Examples of correct code for this rule with { "ul": ["list"], "ol": ["list"] }:
Resources
- ARIA Spec — ARIA Adds Nothing to Default Semantics of Most HTML Elements
- MDN — Identifying SVG as an image