Non-interactive HTML elements, such as <div> and <span>, are not designed to have event handlers. When these elements are given event handlers, it can lead to accessibility issues.
Attaching event handlers to non-interactive HTML elements can lead to significant accessibility issues. These elements, such as <div> and <span>, are not designed to interact with assistive technologies like screen readers, making it difficult for users with disabilities to navigate and interact with the website. Additionally, these elements may not be focusable or provide visual feedback when interacted with, resulting in a confusing and potentially frustrating user experience. Therefore, to maintain an accessible and user-friendly website, event handlers should be used exclusively with interactive elements.
The rule only considers the handlers onClick, onMouseDown, onMouseUp, onKeyPress, onKeyDown, and onKeyUp.
To fix this issue, remove the event handler from the non-interactive element and attach it to an interactive element instead. If the element is not interactive, it should not have an event handler.
void 0} role="button" /> void 0} role="presentation" /> void 0} /> // Interactive element does not require role.