Skip to content

noNoninteractiveElementInteractions

Disallow use event handlers on non-interactive elements.

Non-interactive HTML elements indicate content and containers in the user interface. Non-interactive elements include <main>, <area>, <h1> (,<h2>, etc), <img>, <li>, <ul> and <ol>.

A Non-interactive element does not support event handlers(mouse and key handlers).

<div onClick={() => {}}>button</div>
code-block.jsx:1:1 lint/nursery/noNoninteractiveElementInteractions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Non-interactive element should not have event handler.

> 1 │ <div onClick={() => {}}>button</div>
^^^^^^^^^^^^^^^^^^^^^^^^
2 │

Consider replace semantically interactive element like <button/> or <a href/>.

<button onClick={() => { }}>button</button>
// Adding a role to element does not add behavior.
// If not used semantic HTML elements like `button`, developers need to implement the expected behavior for role(like focusability and key press support)
// See https://www.w3.org/WAI/ARIA/apg/
<div role="button" onClick={() => { }}>button</div>
// The role="presentation" attribute removes the semantic meaning of an element, indicating that it should be ignored by assistive technologies.
// Therefore, it's acceptable to add event handlers to elements with role="presentation" for visual effects or other purposes,
// but users relying on assistive technologies may not be able to interact with these elements.
<div role="presentation" onClick={() => { }}>button</div>
// Hidden from screen reader.
<div onClick={() => {}} aria-hidden />
// Custom component is not checked.
<SomeComponent onClick={() => {}}>button</SomeComponent>
// Spread attributes is not supported.
<div {...{"onClick":() => {}}}>button</div>
biome.json
{
"linter": {
"rules": {
"nursery": {
"noNoninteractiveElementInteractions": "error"
}
}
}
}