Why this matters
Using positive tabIndex values disrupts the natural tab order, confusing users who rely on keyboard navigation or assistive technologies. Stick to tabIndex values of 0 or -1 for predictable and accessible navigation.
Ensure tabIndex values are either 0 or -1. Positive tabIndex values disrupt the natural tab order and can create accessibility issues.
Using positive tabIndex values disrupts the natural tab order, confusing users who rely on keyboard navigation or assistive technologies. Stick to tabIndex values of 0 or -1 for predictable and accessible navigation.
Side-by-side examples engineers can pattern-match during review.
function MyDiv() {
return (
<div>
<span tabIndex="5">foo</span> // Noncompliant
<span tabIndex="3">bar</span> // Noncompliant
<span tabIndex="1">baz</span> // Noncompliant
<span tabIndex="2">qux</span> // Noncompliant
</div>
);
}function MyDiv() {
return (
<div>
<span tabIndex="0">foo</span>
<span tabIndex="-1">bar</span>
<span tabIndex={0}>baz</span>
<span>qux</span>
</div>
);
}function MyDiv() {
return (
<div>
<span tabIndex="5">foo</span> // Noncompliant
<span tabIndex="3">bar</span> // Noncompliant
<span tabIndex="1">baz</span> // Noncompliant
<span tabIndex="2">qux</span> // Noncompliant
</div>
);
}function MyDiv() {
return (
<div>
<span tabIndex="0">foo</span>
<span tabIndex="-1">bar</span>
<span tabIndex={0}>baz</span>
<span>qux</span>
</div>
);
}From the same buckets as this rule.