Skip to content

control-has-associated-label treats options of select component as labels -> false negative #1065

@gilluminate

Description

@gilluminate

A standalone select element with no associated label will pass

<select>
  <option value="ancestors">Ancestors</option>
  <option value="descendants">Descendants</option>
  <option value="all">All</option>
</select>

^ No lint errors

A custom select component with correctly associated label will fail

settings: {
  "jsx-a11y": {
    components: {
      Select: "select",
    },
  },
},
<label htmlFor="my-select">
  Change my value
  <Select id="my-select" options={options} />
</label>

^ Lint errors

...unless the rule also defines options as labels (which is not a correct)

"jsx-a11y/control-has-associated-label": [
  "error",
  { labelAttributes: ["options"] },
],

This violates accessibility rules around select components, which need a proper label association other than the options within it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions