Navigation using the Tab key should be restricted to elements on the page that users can interact with.
The misuse of the tabIndex property can lead to several issues:
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.
<div tabIndex={0}>Save</div>
<button type="button">Save</button>
<div
role="button"
tabIndex={0}
onClick={save}
onKeyDown={event => {
if (event.key === 'Enter' || event.key === ' ') {
save();
}
}}
>
Save
</div>
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>