mouseEventKeyEvents
Reports mouse events without corresponding keyboard events.
✅ This rule is included in the jsx logical preset.
Mouse events should have keyboard equivalents for users who cannot use a mouse. This ensures that functionality is accessible to all users, such as those with limited hardware or personal disabilities.
Specifically:
onMouseOvermust be paired withonFocusonMouseOutmust be paired withonBlur
This is required for WCAG 2.1.1 compliance.
Examples
Section titled “Examples”<div onMouseOver={() => {}} /><div onMouseOut={() => {}} /><div onMouseOver={() => {}} onFocus={() => {}} /><div onMouseOut={() => {}} onBlur={() => {}} />When Not To Use It
Section titled “When Not To Use It”If your application doesn’t use mouse event handlers, or if you use a framework that automatically injects key event handlers for equivalent mouse event handlers, you can disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.