Non-interactive DOM elements are HTML elements that are not designed to be interacted with by the user, for instance <div>,
<span>, and <footer>, etc. They are typically used to structure content and do not have built-in interactivity
or keyboard accessibility.
Interactive handlers, on the other hand, are event handlers that respond to user interactions. These include handlers like onClick,
onKeyDown, onMouseUp, and more. When these handlers are added to an HTML element, they make the element respond to the
specified user interaction.
When non-interactive elements have interactive handlers, it can lead to several problems:
By enforcing that interactive handlers are only used on interactive elements, this rule helps create a more predictable and user-friendly experience for all users, and ensures that web content adheres to accessibility standards and best practices.
The simplest and most recommended way is to replace the non-interactive elements with interactive ones. If for some reason you can’t replace the
non-interactive element, you can add an interactive role attribute to it and manually manage its keyboard event handlers and focus.
Common interactive roles include button, link, checkbox, menuitem, menuitemcheckbox,
menuitemradio, option, radio, searchbox, switch, and textbox.
<div onClick={() => {}} />; // Noncompliant
<div onClick={() => {}} role="button" />;