oxc-project/oxc · error

`{attr_name}` must be accompanied by `onFocus` for accessibi

Error message

`{attr_name}` must be accompanied by `onFocus` for accessibility.

What it means

Raised by jsx-a11y/mouse-events-have-key-events when an element has a mouse event handler (e.g. onMouseOver, onMouseOut) but no corresponding focus handler (onFocus/onBlur). Mouse-only interactions are inaccessible to keyboard users.

Source

Thrown at crates/oxc_linter/src/rules/jsx_a11y/mouse_events_have_key_events.rs:18

use oxc_ast::{AstKind, ast::JSXAttributeValue};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_str::CompactStr;
use schemars::JsonSchema;
use serde::Deserialize;

use crate::{
    AstNode,
    context::LintContext,
    globals::HTML_TAG,
    rule::{DefaultRuleConfig, Rule},
    utils::{get_element_type, get_prop_value, has_jsx_prop},
};

fn miss_on_focus(span: Span, attr_name: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "`{attr_name}` must be accompanied by `onFocus` for accessibility."
    ))
    .with_help("Try to add `onFocus`.")
    .with_label(span)
}

fn miss_on_blur(span: Span, attr_name: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("`{attr_name}` must be accompanied by `onBlur` for accessibility."))
        .with_help("Try to add `onBlur`.")
        .with_label(span)
}

#[derive(Debug, Default, Clone, Deserialize)]
pub struct MouseEventsHaveKeyEvents(Box<MouseEventsHaveKeyEventsConfig>);

#[derive(Debug, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct MouseEventsHaveKeyEventsConfig {

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Add onFocus alongside onMouseOver and onBlur alongside onMouseOut.
  2. Expose the same behavior via focus events so keyboard users get equivalent functionality.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/jsx_a11y/mouse_events_have_key_events.rs:18 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/7b62fab4ed83eca7. Report an issue: GitHub.