oxc-project/oxc · error
A form label must have accessible text.
Error message
A form label must have accessible text.
What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/jsx_a11y/label_has_associated_control.rs:28
use oxc_str::CompactStr;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{
AstNode,
context::LintContext,
rule::Rule,
utils::{get_element_type, get_jsx_attribute_name, has_jsx_prop, is_react_component_name},
};
fn label_has_associated_control_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("A form label must be associated with a control.")
.with_help("Either give the label a `htmlFor` attribute with the id of the associated control, or wrap the label around the control.")
.with_label(span)
}
fn label_has_associated_control_diagnostic_no_label(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("A form label must have accessible text.")
.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.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct LabelHasAssociatedControl(Box<LabelHasAssociatedControlConfig>);
const DEFAULT_CONTROL_COMPONENTS: [&str; 6] =
["input", "meter", "output", "progress", "select", "textarea"];
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct LabelHasAssociatedControlConfig {
/// Maximum depth to search for a nested control.
depth: u8,
/// The type of association required between the label and the control.
assert: Assert,
/// Custom JSX components to be treated as labels.View on GitHub (pinned to e1e7af627c)
Solutions
- Add visible text content to the label.
- Provide an aria-label on the associated control instead of an empty label.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/jsx_a11y/label_has_associated_control.rs:28 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/fda022c3b521dcec.
Report an issue: GitHub.