Skip to content

Commit

Permalink
fix(select): remove aria-owns when options aren't in the DOM
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crisbeto committed Dec 21, 2017
1 parent 3f589cd commit ab657ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,22 @@ describe('MatSelect', () => {
.toContain(options[1].id, `Expected aria-owns to contain IDs of its child options.`);
}));

it('should remove aria-owns when the options are not visible', fakeAsync(() => {
const select = fixture.debugElement.query(By.css('mat-select'));

expect(select.nativeElement.hasAttribute('aria-owns'))
.toBe(true, 'Expected select to have aria-owns while open.');

const backdrop =
overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement;
backdrop.click();
fixture.detectChanges();
flush();

expect(select.nativeElement.hasAttribute('aria-owns'))
.toBe(false, 'Expected select not to have aria-owns when closed.');
}));

it('should set the option id properly', fakeAsync(() => {
let firstOptionID = options[0].id;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class MatSelectTrigger {}
'[attr.aria-required]': 'required.toString()',
'[attr.aria-disabled]': 'disabled.toString()',
'[attr.aria-invalid]': 'errorState',
'[attr.aria-owns]': '_optionIds',
'[attr.aria-owns]': 'panelOpen ? _optionIds : null',
'[attr.aria-multiselectable]': 'multiple',
'[attr.aria-describedby]': '_ariaDescribedby || null',
'[attr.aria-activedescendant]': '_getAriaActiveDescendant()',
Expand Down

0 comments on commit ab657ee

Please sign in to comment.