Skip to content

jsx_a11y/no-noninteractive-tabindex Correctness

This rule is turned on by default.

What it does

This rule checks that non-interactive elements don't have a tabIndex which would make them interactive via keyboard navigation.

Why is this bad?

Tab key navigation should be limited to elements on the page that can be interacted with. Thus it is not necessary to add a tabindex to items in an unordered list, for example, to make them navigable through assistive technology.

These applications already afford page traversal mechanisms based on the HTML of the page. Generally, we should try to reduce the size of the page's tab ring rather than increasing it.

Examples

Examples of incorrect code for this rule:

jsx
<div tabIndex="0" />
<div role="article" tabIndex="0" />
<article tabIndex="0" />
<article tabIndex={0} />

Examples of correct code for this rule:

jsx
<div />
<MyButton tabIndex={0} />
<button />
<button tabIndex="0" />
<button tabIndex={0} />
<div />
<div tabIndex="-1" />
<div role="button" tabIndex="0" />
<div role="article" tabIndex="-1" />
<article tabIndex="-1" />

References

Released under the MIT License.