Skip to main content
ESLint Interlace
Plugin: react-a11yRules

mouse-events-have-key-events

mouse-events-have-key-events rule

Keywords: mouse-events-have-key-events, accessibility, ESLint rule, WCAG, a11y, React accessibility

Require keyboard events with mouse events. This rule is part of eslint-plugin-react-a11y and provides LLM-optimized error messages with fix suggestions.

Quick Summary

AspectDetails
WCAG Criterion2.1.1 Keyboard
SeverityError/Warning (accessibility)
Auto-Fix💡 Suggestions available
CategoryAccessibility
ESLint MCP✅ Optimized for ESLint MCP integration

Rule Details

This rule helps ensure WCAG 2.1.1 compliance by enforcing: Require keyboard events with mouse events

Why This Matters

IssueImpactStandard
AccessibilityScreen reader and assistive technology users affectedWCAG 2.1.1
⚖️ LegalADA/Section 508 compliance riskLegal Requirement
🔍 SEOSearch engines prefer accessible sitesBest Practice

Examples

❌ Incorrect

// Violation of mouse-events-have-key-events
// See rule source for specific examples

✅ Correct

// Compliant with mouse-events-have-key-events
// See rule source for specific examples

Configuration

// eslint.config.js
{
  rules: {
    'react-a11y/mouse-events-have-key-events': 'error'
  }
}

WCAG 2.1 Compliance

This rule helps satisfy:

  • 2.1.1 Keyboard: Require keyboard events with mouse events
  • See RULES.md for all accessibility rules

Further Reading

Version

This rule is available in eslint-plugin-react-a11y v1.0.0+

Known False Negatives

The following patterns are not detected due to static analysis limitations:

Dynamic Variable References

Why: Static analysis cannot trace values stored in variables or passed through function parameters.

// ❌ NOT DETECTED - Prop from variable
const propValue = computedValue;
<Component prop={propValue} /> // Computation not analyzed

Mitigation: Implement runtime validation and review code manually. Consider using TypeScript branded types for validated inputs.

Imported Values

Why: When values come from imports, the rule cannot analyze their origin or construction.

// ❌ NOT DETECTED - Value from import
import { getValue } from './helpers';
processValue(getValue()); // Cross-file not tracked

Mitigation: Ensure imported values follow the same constraints. Use TypeScript for type safety.