Skip to content

fix(checkbox): suppress label warning when aria-label or aria-labelledby is set#1333

Merged
iOvergaard merged 4 commits intov1/devfrom
v1/bugfix/1332-label-mixin-aria-label-warning
Mar 5, 2026
Merged

fix(checkbox): suppress label warning when aria-label or aria-labelledby is set#1333
iOvergaard merged 4 commits intov1/devfrom
v1/bugfix/1332-label-mixin-aria-label-warning

Conversation

@iOvergaard
Copy link
Copy Markdown
Contributor

@iOvergaard iOvergaard commented Mar 5, 2026

Summary

Fixes a false-positive console warning in LabelMixin when aria-label or aria-labelledby is set on a component but no label property is provided — a perfectly valid accessibility pattern (e.g. icon-only buttons, row-selection checkboxes, search inputs without visible labels).

Changes:

  • LabelMixin — warning only fires when none of label, aria-label, or aria-labelledby are present
  • LabelMixinMutationObserver added so dynamic changes to host aria-label/aria-labelledby (e.g. localization updates) trigger a re-render and stay in sync
  • Four components updated to forward host aria-* attributes to their internal native element, with aria-label taking priority over label for the accessible name:
Component Inner element Forwards aria-label Forwards aria-labelledby
uui-boolean-input (checkbox, toggle) <input type="checkbox">
uui-input <input>
uui-button <button> / <a>
uui-color-slider slider div

Accessible name priority: aria-label on host → label property → none (warning)

Test plan

  • New tests added to uui-checkbox covering all four cases: no label (warns), label set, aria-label set, aria-labelledby set
  • Tests assert that #input receives the correct aria-label/aria-labelledby attribute values
  • Warning spy scoped to label-specific messages only — no false positives from unrelated warnings during fixture
  • All 128 tests pass across Chromium, Firefox, and WebKit

Closes #1332

🤖 Generated with Claude Code

…dby is set

LabelMixin now checks for aria-label and aria-labelledby before warning
about a missing label attribute, since both provide valid accessible names
for screen readers without requiring a visible label.

Closes #1332

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 5, 2026 13:26
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 5, 2026

Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1333.westeurope.azurestaticapps.net

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the shared LabelMixin warning logic and adds checkbox tests to avoid console warnings when consumers provide ARIA labeling instead of the label property.

Changes:

  • Update LabelMixin to skip the “needs a label” warning if aria-label or aria-labelledby is present on the host element.
  • Add uui-checkbox tests covering warning behavior for: no label, label, aria-label, and aria-labelledby.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/uui-base/lib/mixins/LabelMixin.ts Changes the missing-label warning condition to consider host aria-label / aria-labelledby.
packages/uui-checkbox/lib/uui-checkbox.test.ts Adds tests validating when the label warning is (not) emitted.

Comment thread packages/uui-base/lib/mixins/LabelMixin.ts
Comment thread packages/uui-checkbox/lib/uui-checkbox.test.ts Outdated
Comment thread packages/uui-checkbox/lib/uui-checkbox.test.ts
…l input

When a host aria-label or aria-labelledby is set (and no label property),
forward the value to the internal #input so screen readers pick it up.
Also tighten the console.warn spy in tests to only catch label-specific
warnings, and add assertions that #input receives the correct attributes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 5, 2026

Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1333.westeurope.azurestaticapps.net

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread packages/uui-boolean-input/lib/uui-boolean-input.element.ts
…ply consistently

- LabelMixin now uses a MutationObserver to watch for aria-label and
  aria-labelledby changes on the host and triggers re-render, so dynamic
  updates (e.g. localization) are forwarded correctly to internal elements
- aria-label on the host now wins over the label property for the accessible
  name on all internal native elements (aria-label is the explicit override)
- Applied to boolean-input, uui-input, uui-button, and uui-color-slider

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 5, 2026

Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1333.westeurope.azurestaticapps.net

Consistent with boolean-input and uui-input — all four components now
forward both aria-label and aria-labelledby from host to inner element.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 5, 2026

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 5, 2026

Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1333.westeurope.azurestaticapps.net

@iOvergaard iOvergaard added the bug Something isn't working label Mar 5, 2026
@iOvergaard iOvergaard merged commit 2e54176 into v1/dev Mar 5, 2026
11 of 12 checks passed
@iOvergaard iOvergaard deleted the v1/bugfix/1332-label-mixin-aria-label-warning branch March 5, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants