Skip to content

Commit ca37709

Browse files
axvermaAkshay Verma
and
Akshay Verma
authored
fix(material/core): mat-optgroup labels are read twice during screen-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]>
1 parent 3f1b1f7 commit ca37709

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<label
1+
<span
22
class="mat-mdc-optgroup-label"
3+
aria-hidden="true"
34
[class.mdc-list-item--disabled]="disabled"
45
[id]="_labelId">
56
<span class="mdc-list-item__text">{{ label }} <ng-content></ng-content></span>
6-
</label>
7+
</span>
78

89
<ng-content select="mat-option, ng-container"></ng-content>

src/material-experimental/mdc-select/select.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ describe('MDC-based MatSelect', () => {
11331133

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

11381138
expect(label.getAttribute('id')).toBeTruthy('Expected label to have an id.');
11391139
expect(group.getAttribute('aria-labelledby'))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<label class="mat-optgroup-label" [id]="_labelId">{{ label }} <ng-content></ng-content></label>
1+
<span class="mat-optgroup-label" aria-hidden="true" [id]="_labelId">{{ label }} <ng-content></ng-content></span>
22
<ng-content select="mat-option, ng-container"></ng-content>

src/material/select/select.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ describe('MatSelect', () => {
11291129

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

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

0 commit comments

Comments
 (0)