{"record":{"id":"fda5bf266fb0a79e","repo":"oxc-project/oxc","slug":"role-role-is-missing-required-aria-props-prop","errorCode":null,"errorMessage":"`{role}` role is missing required aria props {props}.","messagePattern":"`(.+?)` role is missing required aria props (.+?)\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/jsx_a11y/role_has_required_aria_props.rs","lineNumber":14,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{JSXAttributeItem, JSXAttributeValue},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse itertools::Itertools;\n\nuse crate::{AstNode, context::LintContext, rule::Rule, utils::has_jsx_prop_ignore_case};\n\nfn role_has_required_aria_props_diagnostic(span: Span, role: &str, props: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"`{role}` role is missing required aria props {props}.\"))\n        .with_help(format!(\"Add missing aria props {props} to the element with `{role}` role.\"))\n        .and_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct RoleHasRequiredAriaProps;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Enforces that elements with ARIA roles must have all required attributes\n    /// for that role.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Certain ARIA roles require specific attributes to express necessary\n    /// semantics for assistive technology.\n    ///","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jsx_a11y/role_has_required_aria_props.rs#L1-L32","documentation":"This is the `jsx_a11y/role-has-required-aria-props` rule in oxlint. It fires when an element has a `role` but is missing one or more ARIA properties that the ARIA spec requires for that role — e.g. `checkbox` requires `aria-checked`, `slider` requires `aria-valuemin`/`aria-valuemax`/`aria-valuenow`, `heading` requires `aria-level`. Without them, assistive tech announces an incomplete widget.","triggerScenarios":"A JSX opening element with a literal `role` attribute (found via `has_jsx_prop_ignore_case`) whose role, looked up in the embedded ARIA role->required-props table, has required properties, and at least one of those `aria-*` props is absent from the same element.","commonSituations":"Hand-rolled widgets: `role=\"checkbox\"` without `aria-checked`, `role=\"progressbar\"` without `aria-valuenow`, `role=\"heading\"` without `aria-level`; copying example markup that omitted state attributes; refactors that dropped props during component extraction.","solutions":["Add every required `aria-*` prop named in the diagnostic message, bound to real state.","Prefer the native element (`<input type=\"checkbox\">`) which manages required semantics itself.","Double-check dynamic bindings — a conditional `aria-checked={undefined}` still counts as missing."],"exampleFix":"// before\n<span role=\"checkbox\" tabIndex={0} aria-labelledby=\"lbl\">Subscribe</span>\n\n// after\n<span role=\"checkbox\" tabIndex={0} aria-checked={subscribed} aria-labelledby=\"lbl\">Subscribe</span>","handlingStrategy":"validation","validationCode":"npx oxlint --jsx-a11y/role-has-required-aria-props src/","typeGuard":"// Before rendering a role-based widget, assert its required props exist:\nconst hasRequiredAria = (role: string, props: Record<string, unknown>) => {\n  const table: Record<string, string[]> = {\n    checkbox: ['aria-checked'],\n    slider: ['aria-valuemin', 'aria-valuemax', 'aria-valuenow'],\n    heading: ['aria-level'],\n  };\n  return (table[role] ?? []).every((k) => props[k] !== undefined);\n};","tryCatchPattern":null,"preventionTips":["Whenever you write role=\"X\", look up X's required states and add them bound to real state.","Prefer native widgets which manage required semantics for you.","Beware conditionally undefined aria props; they count as missing."],"tags":["jsx-a11y","react","accessibility","aria","widget-semantics","lint"],"backgroundTag":"missing-required-aria-props","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}