Skip to content

fix(button): keep aria-label set outside igxLabel - 22.3.x - #18056

Merged
kdinev merged 2 commits into
22.3.xfrom
simeonoff/fix-18009-button-aria-label-22.3.x
Nov 25, 2026
Merged

kdinev merged 2 commits into
22.3.xfrom
simeonoff/fix-18009-button-aria-label-22.3.x

Conversation

@simeonoff

@simeonoff simeonoff commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Closes #18009

Cherry-pick of #18055 to 22.3.x.

Description

igxButton no longer removes an aria-label set on the button. The [attr.aria-label] host binding is gone. The button writes aria-label with Renderer2 only when igxLabel has a value. When igxLabel is cleared, it removes aria-label only if the attribute still holds the value igxLabel wrote, so a newer native aria-label is kept and a server-rendered value isn't mistaken for an authored one.

The label styles ([igxLabel] base rule, tokens and typography) now skip .igx-button. The selector is [igxLabel]:where(:not(.igx-button)), so specificity stays at (0,1,0).

The button's igxLabel input is deprecated in favor of the native aria-label. The button group now binds [attr.aria-label] instead of [igxLabel]; its rendered output is the same.

Motivation / Context

Since 22.2.0 (#17155), the host binding wrote null when igxLabel was unset, so Angular removed any aria-label the template set, static, i18n-aria-label or bound. Before that, the button set aria-label only when igxLabel had a value, as 21.2.x still does.

The button's igxLabel input shares its name with the [igxLabel] selector of IgxLabelDirective. A button written as igxLabel="...", as the button's JSDoc shows, matched the label CSS and took the label text color. #17987 made this visible, because the label styles are now kept when igx-label is excluded but an included component depends on it.

Type of Change (check all that apply):

  • Bug fix
  • New functionality
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (no functional changes)
  • Documentation
  • Demos
  • CI/CD
  • Tests
  • Changelog
  • Skills/Agents

Component(s) / Area(s) Affected:

Button, Button Group, Theming (label)

How Has This Been Tested?

  • Unit tests
  • Manual testing
  • Automated e2e tests

New specs in button.directive.spec.ts cover a static aria-label, a bound aria-label, no aria-label at all, igxLabel setting and updating aria-label, replacing a static aria-label while set, clearing igxLabel after a newer native aria-label, and clearing it after hydration. Three of them failed before the fix. The button, button group and input group specs and npm run test:styles pass. In the full library run, the only failure is the hierarchical grid test "should skip nested child grids that have no data", which also fails on master.

I compiled the light and dark Material, Indigo, Bootstrap and Fluent presets before and after. The only changes are the [igxLabel] selectors (base, tokens, RTL and typography rules).

I also ran an app that reported the issue against a local build, with SSR. The server HTML has the aria-label from i18n-aria-label, and a button that uses igxLabel gets its aria-label on the server as well. After hydration both keep their aria-label and the button colors, and there are no hydration warnings.

Test Configuration:

  • Angular version: 22.2
  • Browser(s): Chrome
  • OS: macOS

Checklist:

  • All relevant labels have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them
  • Accessibility (ARIA, keyboard navigation, focus management) has been verified

The aria-label host binding wrote null when igxLabel was unset, which
removed any aria-label the template set (regression from #17155). The
button now writes aria-label only through igxLabel and restores the
element's own value when igxLabel is cleared.

Label styles now skip .igx-button, so igxLabel on a button no longer
gets the IgxLabelDirective styles. The button's igxLabel input is
deprecated in favor of aria-label.

Closes #18009
@simeonoff simeonoff added 🐛 bug Any issue that describes a bug button-theme button labels Nov 25, 2026
Copilot AI balanced review requested due to automatic review settings November 25, 2026 12:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Clearing igxLabel can restore stale accessible labels after native aria-label updates or SSR hydration, leaving buttons with incorrect accessible names.

2 open issues
What changed in this PR

Backports #18055 to 22.3.x to address #18009, preserving native button accessibility labels and preventing shared label styles from changing button colors.

Changes:

  • Replaces the button’s aria-label host binding with updates and restoration through igxLabel.
  • Excludes buttons from shared label styles without increasing selector specificity.
  • Deprecates the button’s igxLabel input, updates button-group bindings, and adds regression tests and documentation.
File Description
projects/​igniteui-angular/​directives/​src/​directives/​button/​README.md Documents igxLabel deprecation and the native alternative.
projects/​igniteui-angular/​directives/​src/​directives/​button/​button.directive.ts Implements conditional label updates and restoration.
projects/​igniteui-angular/​directives/​src/​directives/​button/​button.directive.spec.ts Adds native-label preservation and restoration tests.
projects/​igniteui-angular/​core/​src/​core/​styles/​components/​label/​_label-theme.scss Excludes buttons from scoped label tokens.
projects/​igniteui-angular/​core/​src/​core/​styles/​components/​label/​_label-component.scss Excludes buttons from base label styling.
projects/​igniteui-angular/​button-group/​src/​button-group/​button-group-content.component.html Binds button labels directly to aria-label.
CHANGELOG.md Records the fixes and deprecation for 22.3.2.

Review effort: Balanced

Drop the snapshot and restore of the element's own aria-label. Clearing
igxLabel now removes the attribute only if it still holds the value
igxLabel wrote, so a newer native aria-label is kept and a hydrated
server value is not mistaken for an authored one.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Clearing label can incorrectly remove a newer native aria-label with matching text, leaving the button without its authored accessible name.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Equal-value label update can erase the authored accessible name

projects/​igniteui-angular/​directives/​src/​directives/​button/​button.directive.ts:104

In the combined-binding fixture, change ariaLabel from 'Save' to 'Close', run change detection, then clear label: this removes the newer native label because its text matches _label. The unchanged native binding will not write it back, leaving the button without its authored accessible name. Track intervening native writes independently of text equality, and add this equal-value case to the regression test.

2 resolved since last review

Review effort: Balanced

@simeonoff

Copy link
Copy Markdown
Member Author

The equal-value case is a known limit of the ownership check and is intentional. Telling a native write apart from igxLabel's own value when the text is identical would need a MutationObserver on every button, because Angular writes [attr.aria-label] straight to the element. That isn't worth it for an input deprecated in this PR. The igxLabel JSDoc documents that while it has a value it replaces any other aria-label, and the migration path is to use aria-label alone.

@kdinev kdinev added the ✅ status: verified Applies to PRs that have passed manual verification label Nov 25, 2026
@kdinev
kdinev merged commit 84e15aa into 22.3.x Nov 25, 2026
7 checks passed
@kdinev
kdinev deleted the simeonoff/fix-18009-button-aria-label-22.3.x branch November 25, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Any issue that describes a bug button button-theme version: 22.3.x ✅ status: verified Applies to PRs that have passed manual verification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants