Skip to content

Commit bae2830

Browse files
jelbournandrewseguin
authored andcommitted
fix(material/badge): insert inline description for non-interactive hosts (#27025)
The badge current applies `aria-describedby` to surface the developer-provided description. However, assistive technology generally doesn't read these description on non-interactive elements. So, we can take advantage of our handy `InteractivityChecker` and do something different if the host is not focusable; we add the description inline as the next sibling with `.cdk-visually-hidden`. Fixes #26190 (cherry picked from commit f0a5008)
1 parent f09e669 commit bae2830

File tree

4 files changed

+285
-164
lines changed

4 files changed

+285
-164
lines changed

src/dev-app/badge/badge-demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ <h3>Buttons</h3>
2424

2525
<div class="demo-badge">
2626
<h3>Icons</h3>
27-
<mat-icon [matBadge]="badgeContent">
27+
<mat-icon [matBadge]="badgeContent" matBadgeDescription="This is a home indicator">
2828
home
2929
</mat-icon>
3030

src/material/badge/badge.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ background color to `primary`, `accent`, or `warn`.
4848
"region":"mat-badge-color"}) -->
4949

5050
### Accessibility
51-
Badges should be given a meaningful description via `matBadgeDescription`. This description will be
52-
applied, via `aria-describedby` to the element decorated by `matBadge`.
53-
54-
When applying a badge to a `<mat-icon>`, it is important to know that the icon is marked as
55-
`aria-hidden` by default. If the combination of icon and badge communicates some meaningful
56-
information, that information should be surfaced in another way. [See the guidance on indicator
51+
You must provide a meaningful description via `matBadgeDescription`. When attached to an interactive
52+
element, `MatBadge` applies this description to its host via `aria-describedby`. When attached to
53+
a non-interactive element, `MatBadge` appends a visually-hidden, inline description element. The
54+
badge determines interactivity based on whether the host element is focusable.
55+
56+
When applying a badge to a `<mat-icon>`, it is important to know that `<mat-icon>` is
57+
`aria-hidden="true"` by default. If the combination of icon and badge communicates meaningful
58+
information, always surface this information in another way. [See the guidance on indicator
5759
icons for more information](https://material.angular.io/components/icon/overview#indicator-icons).

0 commit comments

Comments
 (0)