{"record":{"id":"c9e59c9c8406e6e2","repo":"oxc-project/oxc","slug":"static-html-elements-with-event-handlers-require-a","errorCode":null,"errorMessage":"Static HTML elements with event handlers require a role.","messagePattern":"Static HTML elements with event handlers require a role\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/jsx_a11y/no_static_element_interactions.rs","lineNumber":27,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_str::CompactStr;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    globals::HTML_TAG,\n    rule::{DefaultRuleConfig, Rule},\n    utils::{\n        get_element_type, get_prop_value, has_jsx_prop, has_jsx_prop_ignore_case, is_abstract_role,\n        is_hidden_from_screen_reader, is_interactive_element, is_interactive_role,\n        is_non_interactive_element, is_non_interactive_role, is_presentation_role,\n    },\n};\n\nfn no_static_element_interactions_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Static HTML elements with event handlers require a role.\")\n        .with_help(\"Add a role attribute to this element, or use a semantic HTML element instead.\")\n        .with_label(span)\n}\n\nconst DEFAULT_HANDLERS: &[&str] =\n    &[\"onClick\", \"onMouseDown\", \"onMouseUp\", \"onKeyPress\", \"onKeyDown\", \"onKeyUp\"];\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct NoStaticElementInteractions(Box<NoStaticElementInteractionsConfig>);\n\nimpl std::ops::Deref for NoStaticElementInteractions {\n    type Target = NoStaticElementInteractionsConfig;\n\n    fn deref(&self) -> &Self::Target {\n        &self.0\n    }\n}\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/oxc-project/oxc/blob/1f902a69625cd14e6d8dc58feca94da099d2d251/crates/oxc_linter/src/rules/jsx_a11y/no_static_element_interactions.rs#L9-L45","documentation":"This is the `jsx_a11y/no-static-element-interactions` rule in oxlint. It fires when a static (non-interactive, non-interactive-role, non-hidden) HTML element carries one of the default interaction handlers — `onClick`, `onMouseDown`, `onMouseUp`, `onKeyPress`, `onKeyDown`, `onKeyUp` (see `DEFAULT_HANDLERS`) or a configured `handlers` entry — without any ARIA role. A clickable `<div>` with no role is invisible as an operable control to assistive tech.","triggerScenarios":"A JSX element whose type is a static HTML tag (per `HTML_TAG` + `is_non_interactive_element`), carrying a handler from the checked list, while `get_prop_value` finds no `role` attribute, the role is not presentation/abstract, and the element is not hidden from screen readers.","commonSituations":"Clickable div cards, drag-and-drop surfaces, dismiss-on-click overlays, custom cells in data grids; the single most common violation when a team first enables jsx-a11y recommended.","solutions":["Replace the static element with `<button>` (styled to reset defaults) so semantics come free.","Add an appropriate `role` (e.g. `role=\"button\"`) plus `tabIndex={0}` and keyboard handlers when a real button is impossible.","Extend the rule's `handlers` config for legitimate non-pointer cases like `onMouseDown` on drag containers.","Disable inline only for genuinely mouse-only affordances (rare; prefer `role=\"presentation\"` + documented reason)."],"exampleFix":"// before\n<div onClick={() => setOpen(true)}>Show details</div>\n\n// after\n<button type=\"button\" onClick={() => setOpen(true)}>Show details</button>","handlingStrategy":"validation","validationCode":"npx oxlint --jsx-a11y/no-static-element-interactions src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use <button> for click targets; style resets are cheaper than ARIA repairs.","If you must keep a div, pair role + tabIndex + onKeyDown together.","Extend the handlers config for legit non-pointer cases instead of disabling the rule."],"tags":["jsx-a11y","react","accessibility","event-handlers","aria-roles","lint"],"backgroundTag":"static-element-interactions","analyzedSha":"1f902a69625cd14e6d8dc58feca94da099d2d251","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}