Skip to content

Commit 4a03497

Browse files
crisbetojelbourn
authored andcommitted
fix(select): remove aria-owns when options aren't in the DOM (angular#9091)
Removes the select's `aria-owns` attribute when the options aren't in the DOM, in order to avoid pointing non-existing elements. Fixes angular#7023.
1 parent ce2487e commit 4a03497

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/lib/select/select.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,22 @@ describe('MatSelect', () => {
16591659
.toContain(options[1].id, `Expected aria-owns to contain IDs of its child options.`);
16601660
}));
16611661

1662+
it('should remove aria-owns when the options are not visible', fakeAsync(() => {
1663+
const select = fixture.debugElement.query(By.css('mat-select'));
1664+
1665+
expect(select.nativeElement.hasAttribute('aria-owns'))
1666+
.toBe(true, 'Expected select to have aria-owns while open.');
1667+
1668+
const backdrop =
1669+
overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement;
1670+
backdrop.click();
1671+
fixture.detectChanges();
1672+
flush();
1673+
1674+
expect(select.nativeElement.hasAttribute('aria-owns'))
1675+
.toBe(false, 'Expected select not to have aria-owns when closed.');
1676+
}));
1677+
16621678
it('should set the option id properly', fakeAsync(() => {
16631679
let firstOptionID = options[0].id;
16641680

src/lib/select/select.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class MatSelectTrigger {}
184184
'[attr.aria-required]': 'required.toString()',
185185
'[attr.aria-disabled]': 'disabled.toString()',
186186
'[attr.aria-invalid]': 'errorState',
187-
'[attr.aria-owns]': '_optionIds',
187+
'[attr.aria-owns]': 'panelOpen ? _optionIds : null',
188188
'[attr.aria-multiselectable]': 'multiple',
189189
'[attr.aria-describedby]': '_ariaDescribedby || null',
190190
'[attr.aria-activedescendant]': '_getAriaActiveDescendant()',

0 commit comments

Comments
 (0)