ESLint says an element with role="button" must be focusable
Elements with the 'button' interactive role must be focusableShort answer
The rule jsx-a11y/interactive-supports-focus flags an element that has an interactive role and a mouse or key handler but cannot receive keyboard focus. The best fix is a native button element. If you must keep the div, add tabIndex={0} plus a key handler so Enter and Space work. tabIndex={-1} only makes it focusable by script.
Fix it fast
1Find out which cause you have
Run ESLint on the one file and read the rule id and line number. The message ends with the rule name, and the element on that line shows which of the causes below applies.
npx eslint src/components/Toolbar.jsx2Match what you see, then jump to its fix
- 1
The flagged line is <div role="button" onClick={...}> or <span role="button" onClick={...}> with no tabIndexA div or span plays a button but is not in the tab orderFix - 2
The element cannot become a button, for example because a library injects its markupThe element must stay a div, so it needs tabIndex and key handlingFix - 3
Elements with the 'button' interactive role must be tabbable, while the element already has tabIndex={-1}tabIndex is -1, which is focusable but not tabbableFix - 4
The flagged line is <a role="button" onClick={...}> without hrefAn anchor with role="button" has no hrefFix
- 1
What does the error look like?
Elements with the 'button' interactive role must be focusableElements with the 'button' interactive role must be tabbablejsx-a11y/interactive-supports-focus
Cause 1 of 4
A div or span plays a button but is not in the tab order
1Check
An element with an interactive role and an event handler must be focusable. A div has no focus behaviour of its own, so keyboard users cannot reach it.
grep -rn 'role="button"' src2Fix
Replace it with a real button element. The rule's documentation lists a button as inherently focusable, so the error goes away and the element joins the tab order.
// before
<div role="button" onClick={save}>Save</div>
// after
<button onClick={save}>Save</button>3Verify
Run ESLint on the file again. The error is gone, and Tab now stops on the control.
npx eslint src/components/Toolbar.jsxConfirmed by github.com
Cause 2 of 4
The element must stay a div, so it needs tabIndex and key handling
1Check
tabIndex={0} puts the element in the tab order and clears the lint error, but a focusable role="button" element also has to react to the keyboard. The ARIA button pattern says Space and Enter activate a button.
grep -rn 'role="button"' src | grep -v onKeyDown2Fix
Add tabIndex={0} and a key handler for Enter and Space.
<div
role="button"
tabIndex={0}
onClick={save}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
save();
}
}}
>
Save
</div>3Verify
Tab to the element and press Enter and Space. Then run ESLint again.
npx eslint src/components/Toolbar.jsxConfirmed by w3.org
Cause 3 of 4
tabIndex is -1, which is focusable but not tabbable
1Check
The rule documents an option named tabbable. Roles listed there, with button among them in the documented example, need a place in the tab ring, which means tabIndex 0. A value of -1 is only for items inside a composite widget such as a menu.
grep -rn 'tabIndex={-1}' src2Fix
Use tabIndex={0} for a standalone button. Keep -1 only for the non-active items of a menu, tab list or similar group that you move through with arrow keys.
<div role="button" tabIndex={0} onClick={save} onKeyDown={onKey}>Save</div>3Verify
Run ESLint on the file.
npx eslint src/components/Toolbar.jsxConfirmed by github.com
Cause 4 of 4
An anchor with role="button" has no href
1Check
An anchor without an href is not focusable, so the role does not rescue it. The rule's own failing example is exactly this.
grep -rn '<a ' src | grep -v href2Fix
If it navigates, give it a real href. If it runs an action, make it a button.
// navigation
<a href="/next">Next page</a>
// action
<button type="button" onClick={showNextPage}>Next page</button>3Verify
Run ESLint on the file.
npx eslint src/components/Toolbar.jsxConfirmed by github.com
How do I stop it coming back?
- Start from native elements: button for actions, a with href for navigation, input for fields. Reach for role only when no native element exists.
- Keep the jsx-a11y recommended config on in CI, so a clickable div fails the build and never reaches review.
- After any change to a custom control, press Tab, Enter and Space on it in the browser once.
- Do not silence the rule with an eslint-disable comment; the keyboard users it protects are real.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
ESLint says an anchor needs a valid, navigable href in React
jsx-a11y/anchor-is-valid
The rule wants every <a> to be a real link.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fix