Navigation using the Tab key should be restricted to elements on the page that users can interact with.

Why is this an issue?

The misuse of the tabIndex property can lead to several issues:

How to fix it

If the element is not meant to be interactive, remove the tabIndex property or set it to -1 so it is skipped by sequential keyboard navigation.

If the element is meant to be interactive, prefer a native interactive element such as <button> or <a href>. When a custom widget is required, give it the appropriate interactive role, keep it keyboard reachable, and implement the keyboard behavior that role expects.

Code examples

Noncompliant code example

<div tabIndex={0}>Save</div>

Compliant solution

<button type="button">Save</button>

Compliant solution

<div
  role="button"
  tabIndex={0}
  onClick={save}
  onKeyDown={event => {
    if (event.key === 'Enter' || event.key === ' ') {
      save();
    }
  }}
>
  Save
</div>

Exception

This rule accepts tabIndex={0} on elements with role="tabpanel". This matches the WAI-ARIA Tabs pattern, which allows the tabpanel itself to receive focus when its first meaningful content is not focusable.

<div role="tabpanel" tabIndex={0}>
  {content}
</div>

Resources

Documentation