{"record":{"id":"c5171e9274204949","repo":"oxc-project/oxc","slug":"missing-value-for-aria-labelledby-attribute","errorCode":null,"errorMessage":"Missing value for `aria-labelledby` attribute.","messagePattern":"Missing value for `aria-labelledby` attribute\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/jsx_a11y/alt_text.rs","lineNumber":42,"sourceCode":"        .with_label(span)\n}\n\nfn missing_alt_value(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Invalid `alt` value.\")\n        .with_help(\n            \"Must have meaningful value for `alt` prop. Use alt=\\\"\\\" for presentational images.\",\n        )\n        .with_label(span)\n}\n\nfn aria_label_value(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Missing value for `aria-label` attribute.\")\n        .with_help(\"Give `aria-label` a meaningful value. Prever the `alt` attribute over `aria-label` for images.\")\n        .with_label(span)\n}\n\nfn aria_labelled_by_value(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Missing value for `aria-labelledby` attribute.\")\n        .with_help(\"Give `aria-labelledby` an ID to a label element. Prefer the `alt` attribute over `aria-labelledby` for images.\")\n        .with_label(span)\n}\n\nfn prefer_alt(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"ARIA used where native HTML could suffice.\")\n        .with_help(\"Prefer alt=\\\"\\\" over presentational role. Native HTML attributes should be preferred for accessibility before resorting to ARIA attributes.\")\n        .with_label(span)\n}\n\nfn object(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Missing alternative text.\")\n        .with_help(\"Embedded <object> elements must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.\")\n        .with_label(span)\n}\n\nfn area(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Missing alternative text.\")","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jsx_a11y/alt_text.rs#L24-L60","documentation":"This is the oxlint `jsx-a11y/alt-text` diagnostic for an `img` with neither `alt` nor a valued `aria-label`, but with an `aria-labelledby` attribute that has no usable value. `aria-labelledby` must reference the id of a label element; an empty or undefined value leaves the image unnamed.","triggerScenarios":"`img_rule` finds an `aria-labelledby` prop (after no `alt` and no valid `aria-label`) where the value is an empty string literal or an undefined/non-expression container per `aria_label_has_value`.","commonSituations":"Passing a label id that is conditionally computed and can be `undefined`; refactors that renamed the target element's id but left `aria-labelledby=\"\"` placeholders.","solutions":["Point `aria-labelledby` at a real element id: `aria-labelledby=\"chart-caption\"` next to `<p id=\"chart-caption\">`.","Prefer plain `alt` text when there is no visible caption to reference.","Ensure the expression feeding the attribute never renders empty."],"exampleFix":"// before\n<img src={src} aria-labelledby=\"\" />\n\n// after\n<p id=\"hero-caption\">Sunrise over the bay</p>\n<img src={src} aria-labelledby=\"hero-caption\" />","handlingStrategy":"validation","validationCode":"// Render aria-labelledby only when the target id is known\nconst captionId = caption ? 'hero-caption' : undefined;\n<>\n  {caption && <p id=\"hero-caption\">{caption}</p>}\n  <img src={src} aria-labelledby={captionId} alt=\"\" />\n</>","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep label ids in a constant shared by the caption and the img so they cannot drift empty.","When no visible caption exists, use `alt` instead of an empty aria-labelledby.","CI-run oxlint jsx-a11y to catch regressions."],"tags":["jsx-a11y","accessibility","aria","alt-text","react","lint","oxlint"],"backgroundTag":"jsx-a11y-alt-text","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"}