nonInteractiveElementInteractions
Reports non-interactive elements with interactive event handlers.
✅ This rule is included in the jsxlogicalandlogicalStrictpresets.
Non-interactive HTML elements and non-interactive ARIA roles indicate content and containers in the user interface. These elements should not have interactive event handlers because they are not designed to be interactive.
Non-interactive elements include <main>, <area>, <h1> through <h6>, <p>, <img>, <li>, <ul>, and <ol>.
Non-interactive ARIA roles include article, banner, complementary, img, listitem, main, navigation, region, and tooltip.
When you need to add interactivity, use native interactive elements like <button> or <a>, or add an appropriate interactive role to the element.
This is required for WCAG 4.1.2 compliance.
Examples
Section titled “Examples”<JSX.IntrinsicElements.h1: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>
h1 DOMAttributes<HTMLHeadingElement>.onClick?: MouseEventHandler<HTMLHeadingElement> | undefined
onClick={() => {}}>Heading</JSX.IntrinsicElements.h1: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>
h1><JSX.IntrinsicElements.main: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>
main DOMAttributes<HTMLElement>.onKeyDown?: KeyboardEventHandler<HTMLElement> | undefined
onKeyDown={const handler: any
handler}>Content</JSX.IntrinsicElements.main: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>
main>;<JSX.IntrinsicElements.img: DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>
img DOMAttributes<HTMLImageElement>.onClick?: MouseEventHandler<HTMLImageElement> | undefined
onClick={const handleClick: any
handleClick} ImgHTMLAttributes<HTMLImageElement>.src?: string | undefined
src="image.png" />;<JSX.IntrinsicElements.section: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>
section DOMAttributes<HTMLElement>.onClick?: MouseEventHandler<HTMLElement> | undefined
onClick={const handler: any
handler} HTMLAttributes<HTMLElement>.role?: AriaRole | undefined
role="article" />;<JSX.IntrinsicElements.h1: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>
h1> <JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button DOMAttributes<HTMLButtonElement>.onClick?: MouseEventHandler<HTMLButtonElement> | undefined
onClick={() => {}}>Heading</JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button></JSX.IntrinsicElements.h1: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>
h1><JSX.IntrinsicElements.h1: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>
h1 DOMAttributes<HTMLHeadingElement>.onClick?: MouseEventHandler<HTMLHeadingElement> | undefined
onClick={() => {}} HTMLAttributes<HTMLHeadingElement>.role?: AriaRole | undefined
role="button"> Heading</JSX.IntrinsicElements.h1: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>
h1><JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button DOMAttributes<HTMLButtonElement>.onClick?: MouseEventHandler<HTMLButtonElement> | undefined
onClick={() => {}}>Click me</JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button><JSX.IntrinsicElements.section: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>
section DOMAttributes<HTMLElement>.onClick?: MouseEventHandler<HTMLElement> | undefined
onClick={const handler: any
handler} HTMLAttributes<HTMLElement>.role?: AriaRole | undefined
role="button" />;When Not To Use It
Section titled “When Not To Use It”If you are using a framework that automatically handles accessibility for non-interactive elements with event handlers, you can disable this rule.
Further Reading
Section titled “Further Reading”- WCAG 4.1.2: Name, Role, Value
- WAI-ARIA Authoring Practices Guide - Design Patterns and Widgets
- WAI-ARIA roles