{"record":{"id":"64a2d4c679a4509f","repo":"oxc-project/oxc","slug":"a-form-label-must-be-associated-with-a-control","errorCode":null,"errorMessage":"A form label must be associated with a control.","messagePattern":"A form label must be associated with a control\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/jsx_a11y/label_has_associated_control.rs","lineNumber":22,"sourceCode":"    AstKind,\n    ast::{JSXAttributeItem, JSXAttributeValue, JSXChild, JSXElement},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse 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)]","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jsx_a11y/label_has_associated_control.rs#L4-L40","documentation":"Raised by jsx-a11y/label-has-associated-control when a <label> is not linked to any form control, either via htmlFor pointing to an input id or by nesting the control inside the label. Unassociated labels are ignored by screen readers.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/jsx_a11y/label_has_associated_control.rs:22 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add htmlFor to the label matching the control's id.","Wrap the input inside the label element.","Add aria-label to the control if a visible label is not possible."],"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"}