Skip to content

fix(material/core): mat-optgroup labels are read twice during screen-reader page navigation #21858

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

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/material-experimental/mdc-core/option/optgroup.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<label
<span
class="mat-mdc-optgroup-label"
aria-hidden="true"
[class.mdc-list-item--disabled]="disabled"
[id]="_labelId">
<span class="mdc-list-item__text">{{ label }} <ng-content></ng-content></span>
</label>
</span>

<ng-content select="mat-option, ng-container"></ng-content>
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ describe('MDC-based MatSelect', () => {

it('should set the `aria-labelledby` attribute', fakeAsync(() => {
let group = groups[0];
let label = group.querySelector('label')!;
let label = group.querySelector('.mat-mdc-optgroup-label') as HTMLElement;

expect(label.getAttribute('id')).toBeTruthy('Expected label to have an id.');
expect(group.getAttribute('aria-labelledby'))
Expand Down
2 changes: 1 addition & 1 deletion src/material/core/option/optgroup.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<label class="mat-optgroup-label" [id]="_labelId">{{ label }} <ng-content></ng-content></label>
<span class="mat-optgroup-label" aria-hidden="true" [id]="_labelId">{{ label }} <ng-content></ng-content></span>
Copy link
Member

Choose a reason for hiding this comment

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

The same fix will have to be applied to the MDC-based option group in src/material-experimental/mdc-core/option/optgroup.html.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the changes to src/material-experimental/mdc-core/option/optgroup.html.

I described the a11y issues I saw in #21847 (with ChromeVox and with VoiceOver + Chrome). I believe removing the group labels from the a11y tree would stop the double-reading in these cases without impacting browsers that do not have this issue. I could provide some screen recordings if that would help.

<ng-content select="mat-option, ng-container"></ng-content>
2 changes: 1 addition & 1 deletion src/material/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ describe('MatSelect', () => {

it('should set the `aria-labelledby` attribute', fakeAsync(() => {
let group = groups[0];
let label = group.querySelector('label')!;
let label = group.querySelector('span')!;

expect(label.getAttribute('id')).toBeTruthy('Expected label to have an id.');
expect(group.getAttribute('aria-labelledby'))
Expand Down