Skip to content

fix(badge): put matBadgeDescription on host instead of badge element #23400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

zarend
Copy link
Contributor

@zarend zarend commented Aug 18, 2021

Description from git commit

Fixes a screenreader issue on the mat-badge component where
screenreaders did not read the matBadgeDescription for badges hosted
on button elements.

Example:

<button mat-badge="2" matBadgeDescription="2 unread messages">open
messages</button>

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 of matBadge for the aria-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 exposes aria-hidden.

@zarend zarend added Accessibility This issue is related to accessibility (a11y) area: material/badge labels Aug 18, 2021
@zarend zarend requested review from crisbeto and amysorto August 18, 2021 19:17
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 18, 2021
Fixes a screenreader issue on the mat-badge component where
screenreaders did not read the `matBadgeDescription` for badges hosted
on `button` elements.

Example:
```<button mat-badge="2" matBadgeDescription="2 unread messages">open
messages</button>```

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.
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM

private _updateHostAriaDescription(newDescription: string, oldDescription: string): void {
// ensure content available before setting label
const content = this._updateTextContent();
this._updateTextContent();
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think that we can also make it so that _updateTextContent doesn't return the badge element. This is the only place where the return value is used.

@jelbourn
Copy link
Member

@zarend I think this PR is superseded by #23562
(I wasn't aware you had sent this PR until I was looking through open PRs this morning)

@zarend
Copy link
Contributor Author

zarend commented Sep 22, 2021

closing in favor of #23562

@zarend zarend closed this Sep 22, 2021
@zarend zarend deleted the badge branch September 22, 2021 15:59
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Accessibility This issue is related to accessibility (a11y) area: material/badge cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants