Skip to content

Commit 80a338a

Browse files
committed
fix(select): remove aria-owns when options aren't in the DOM
Removes the select's `aria-owns` attribute when the options aren't in the DOM, in order to avoid pointing non-existing elements. Fixes #7023.
1 parent c3d7cd9 commit 80a338a

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
@@ -1657,6 +1657,22 @@ describe('MatSelect', () => {
16571657
.toContain(options[1].id, `Expected aria-owns to contain IDs of its child options.`);
16581658
}));
16591659

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

src/lib/select/select.ts

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

0 commit comments

Comments
 (0)