Skip to content
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

fix(material/select): don't announce selected value multiple times #24831

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mhaertwig
Copy link
Contributor

@mhaertwig mhaertwig commented Apr 25, 2022

Screen readers announce the selected value multiple times. NVDA e.g. reads "Favorite food Pizza Pizza combobox Pizza collapsed".

  1. First, the Screen Reader (SR) reads the value of the label (see 1st aria-labelledby): "Favorite food"
  2. SR reads the content of the combobox (because of the label's aria-owns attribute): "Pizza"
  3. SR reads the value of the combobox (see 2nd aria-labelledby): "Pizza"
  4. SR reads the content of the combobox again: "Pizza"

To fix this, an aria-hidden attribute is added to the element containing the selected value. NVDA e.g. now reads "Favorite food Pizza combobox collapsed".

Successfully tested with NVDA, JAWS, Narrator and the Screen Reader Chrome plugin.

Closes #24899

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.

@zarend can you take a look as well and potentially try this out with ChromeVox?

@mhaertwig mhaertwig force-pushed the feature/select-accessibility2 branch from bc44d03 to 5144f43 Compare May 10, 2022 08:49
Screen readers announce the selected value multiple times. NVDA e.g. reads "Favorite food Pizza Pizza combobox Pizza collapsed".

1. First, the Screen Reader (SR) reads the value of the label (see 1st `aria-labelledby`): "Favorite food"
2. SR reads the content of the combobox: "Pizza"
3. SR reads the value of the combobox (see 2nd `aria-labelledby`): "Pizza"
4. SR reads the content of the combobox again: "Pizza"

To fix this, an `aria-hidden` attribute is added to the element containing the selected value. NVDA e.g. now reads "Favorite food Pizza combobox collapsed"
@mhaertwig mhaertwig force-pushed the feature/select-accessibility2 branch from 5144f43 to 8f4d839 Compare May 10, 2022 08:54
@Joeh89
Copy link

Joeh89 commented Jul 20, 2022

The accessible name of the combobox shouldn't contain the dropdown value as well. This is not best practice. Same for the label tag, it's unnecessary since it only works for native html (select and input). The aria-owns lets the screen reader know that despite the element being lower on the DOM, it should be focused on it first before the element it owns. So this should be kept.

My suggestion for the fix would be:

  1. Replacing label tag with div tag and removing the 'for' attribute from it. 'Label' only works for native html (select and input tags), it doesn't work for mat-select even if it has a role="combobox". The 'for' attribute is creating an unnecessary link to the field since aria-labelledby already refers to the inner text of the label (hopefully changing to div) element.
  2. Remove the second id in the aria-labelledby as the screen reader already is capturing the value of the dropdown through javascript.

@anbalase
Copy link

anbalase commented May 9, 2023

bump

@josephperrott josephperrott requested a review from a team as a code owner December 18, 2024 17:40
@josephperrott josephperrott requested review from crisbeto and amysorto and removed request for a team December 18, 2024 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(mat-select): The selection is repeated twice (+) in screen readers
4 participants