oxc-project/oxc · error
Enforce a clickable non-interactive element has at least one
Error message
Enforce a clickable non-interactive element has at least one keyboard event listener.
What it means
Fires from jsx-a11y/click-events-have-key-events when a visible, non-interactive element (like a div) has an onClick handler but no keyboard event listener (onKeyDown/onKeyUp/onKeyPress). The run visitor checks non-interactive, screen-reader-visible elements with click handlers and the helper explains the keyboard-accessibility requirement.
Source
Thrown at crates/oxc_linter/src/rules/jsx_a11y/click_events_have_key_events.rs:18
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{
AstNode,
context::LintContext,
globals::HTML_TAG,
rule::Rule,
utils::{
get_element_type, has_jsx_prop, is_hidden_from_screen_reader, is_interactive_element,
is_presentation_role,
},
};
fn click_events_have_key_events_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Enforce a clickable non-interactive element has at least one keyboard event listener.")
.with_help("Visible, non-interactive elements with click handlers must have one of `keyup`, `keydown`, or `keypress` listener.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct ClickEventsHaveKeyEvents;
declare_oxc_lint!(
/// ### What it does
///
/// Enforce onClick is accompanied by at least one of the following: onKeyUp, onKeyDown, onKeyPress.
///
/// ### Why is this bad?
///
/// Coding for the keyboard is important for users with physical disabilities who cannot use a mouse, AT compatibility, and screen reader users.
/// This does not apply for interactive or hidden elements.
///
/// ### ExamplesView on GitHub (pinned to e1e7af627c)
Solutions
- Add an `onKeyDown` (or onKeyUp/onKeyPress) handler providing equivalent keyboard behavior
- Use an interactive element such as `<button>` instead of a clickable div
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/jsx_a11y/click_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/ee51db9882ce2cab.
Report an issue: GitHub.