Skip to content

Commit b8c900c

Browse files
crisbetommalerba
authored andcommitted
fix(select): wrong option amount being read out by NVDA (#5181)
Fixes an issue that caused the wrong amount of options to be read out by NVDA. E.g. if the select has 3 options, NVDA reads out "<value> selected, 2 of 4". The issue seems to come from the fact that NVDA considers the trigger as one of the options, potentially because it's clickable.
1 parent 4d3919b commit b8c900c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/lib/select/select.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
<div class="mat-select-trigger" cdk-overlay-origin (click)="toggle()" #origin="cdkOverlayOrigin" #trigger>
1+
<div
2+
cdk-overlay-origin
3+
class="mat-select-trigger"
4+
aria-hidden="true"
5+
(click)="toggle()"
6+
#origin="cdkOverlayOrigin"
7+
#trigger>
28
<span
39
class="mat-select-placeholder"
410
[class.mat-floating-placeholder]="_selectionModel.hasValue()"

src/lib/select/select.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,15 @@ describe('MdSelect', () => {
17281728
expect(document.activeElement).toBe(select, 'Expected select element to be focused.');
17291729
});
17301730

1731+
// Having `aria-hidden` on the trigger avoids issues where
1732+
// screen readers read out the wrong amount of options.
1733+
it('should set aria-hidden on the trigger element', () => {
1734+
const trigger = fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement;
1735+
1736+
expect(trigger.getAttribute('aria-hidden'))
1737+
.toBe('true', 'Expected aria-hidden to be true when the select is open.');
1738+
});
1739+
17311740
});
17321741

17331742
describe('for options', () => {

0 commit comments

Comments
 (0)