{"record":{"id":"fda022c3b521dcec","repo":"oxc-project/oxc","slug":"a-form-label-must-have-accessible-text","errorCode":null,"errorMessage":"A form label must have accessible text.","messagePattern":"A form label must have accessible text\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/jsx_a11y/label_has_associated_control.rs","lineNumber":28,"sourceCode":"use oxc_str::CompactStr;\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::Rule,\n    utils::{get_element_type, get_jsx_attribute_name, has_jsx_prop, is_react_component_name},\n};\n\nfn label_has_associated_control_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"A form label must be associated with a control.\")\n        .with_help(\"Either give the label a `htmlFor` attribute with the id of the associated control, or wrap the label around the control.\")\n        .with_label(span)\n}\n\nfn label_has_associated_control_diagnostic_no_label(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"A form label must have accessible text.\")\n        .with_help(\"Ensure the label either has text inside it or is accessibly labelled using an attribute such as `aria-label`, or `aria-labelledby`. You can mark more attributes as accessible labels by configuring the `labelAttributes` option.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct LabelHasAssociatedControl(Box<LabelHasAssociatedControlConfig>);\n\nconst DEFAULT_CONTROL_COMPONENTS: [&str; 6] =\n    [\"input\", \"meter\", \"output\", \"progress\", \"select\", \"textarea\"];\n\n#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct LabelHasAssociatedControlConfig {\n    /// Maximum depth to search for a nested control.\n    depth: u8,\n    /// The type of association required between the label and the control.\n    assert: Assert,\n    /// Custom JSX components to be treated as labels.","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jsx_a11y/label_has_associated_control.rs#L10-L46","documentation":"Raised by jsx-a11y/label-has-associated-control (labelHasAssociatedControl variant) when a label exists and is associated with a control but contains no accessible text. Empty labels provide no information to assistive technology.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/jsx_a11y/label_has_associated_control.rs:28 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add visible text content to the label.","Provide an aria-label on the associated control instead of an empty label."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}