Skip to content

False positive: aria-label should not be flagged as "not allowed" on a <label> associated with a labelable element #78

@unekinn

Description

@unekinn

Describe the bug

ARC Toolkit incorrectly flags an error, "ARIA attribute is not allowed: The aria-label attribute is not allowed on the generic role", for aria-label on a <label> element that wraps an <input>.

ARC appears to unconditionally treat <label> as having the generic role, but the ARIA in HTML specification distinguishes two cases:

If a label element is implicitly or explicitly associated with a labelable element then no role

Otherwise […] any role, though generic SHOULD NOT be used.

When the label is associated with a labelable element (as in the reproduction case below), it has "no role" — not generic. Naming is only prohibited "if exposed as the generic role, or if exposed as another role which prohibits naming." Since the label has no role, this condition does not apply, and the spec falls through to:

Otherwise, global aria-* attributes.

aria-label is a global ARIA attribute, so it is permitted in this case.

To Reproduce

  1. Go to this example from Designsystemet.no's storybook
  2. Run tests on the page in ARC Toolkit
  3. See that an error is flagged for each of the labels

Expected behavior

No error should be flagged, since the <label> is implicitly associated with the <input type="radio"> (a labelable element) and therefore has "no role", not generic.

Screenshots

Screenshot showing three instances of 'ARIA attribute is not allowed' with description: 'The aria-label attribute is not allowed on the generic role'

Version information

  • Browser and version: Chrome 149.0.7827.54 (Official Build) (arm64)
  • ARC Toolkit version: 5.7.10

Additional context

Chrome's accessibility tree confirms the aria-label is functioning correctly. The wrapped <input> receives its accessible name from the label:

Name: "Venstrestilt"
  From label (wrapped): label "Venstrestilt"
Role: `radio`

This pattern is used by Designsystemet to improve accessibility in a Toggle group with icon-only items, by wrapping each item in a Tooltip.

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