fix(badge): put matBadgeDescription
on host instead of badge element
#23400
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description from git commit
Fixes a screenreader issue on the mat-badge component where
screenreaders did not read the
matBadgeDescription
for badges hostedon
button
elements.Example:
As tested on Chromevox with Chrome browser, screenreader reads "open
messages" and does not read "2 unread messages". Screenreader does not
allow navigation to the badge element.
This happens because
button
's are not supposed to have multiple lines.Solution is to align with tooltip by making the badge element
aria-hidden and applying the
matBadgeDescription
to the host element.Why this is a draft
This is still a draft because we need to determine how to handle when a
matBadgeDescription
is not provided.Exhibit A
<span matBadge=”2”>Open messages</span>
Previously, screenreaders could navigate to the badge element, which would be announced as "2" in this example. This change hides the badge element from screenreaders, so the button would be announced as "Open messages"
Our options are to either not put an aria-describedby at all when
matBadgeDescription
is missing, or fallback to using the content ofmatBadge
for thearia-describedby
.I'm leaning towards no doing a fallback. If the app developer does not provide a
matBadgeDescription
then screenreaders will not read the badge. A developer might want to explicitly hide the badge from screen readers and there is nothing in the API that exposesaria-hidden
.