Skip to content

Commit

Permalink
fix(material/core): mat-optgroup labels are read twice during screen-…
Browse files Browse the repository at this point in the history
…reader page navigation. (#21858)

Fixed by adding aria-hidden="true" to the <label> elements.
While screenreaders will still announce the label text for the group they will skip over the actual label element.
Additionally, changed the <label> to a <span> to make it clear that the text is visual only.

Co-authored-by: Akshay Verma <[email protected]>
(cherry picked from commit ca37709)
  • Loading branch information
axverma authored and andrewseguin committed Feb 18, 2021
1 parent e227ebd commit fad83cb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
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>
<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

0 comments on commit fad83cb

Please sign in to comment.