fix(autocomplete): adding aria-activedescendant while closed if autoActiveFirstOption is enabled (#14455)

Fixes the autocomplete trigger setting its `aria-activedescendant` attribute while the panel is closed and the options aren't in the DOM, if the `autoActiveFirstOption` is enabled.

Fixes #14453.
This commit is contained in:
Kristiyan Kostadinov
2018-12-20 19:27:43 +01:00
committed by Jeremy Elbourn
parent 0398d53bae
commit f3065cccaf
2 changed files with 24 additions and 1 deletions
+1 -1
View File
@@ -102,7 +102,7 @@ export function getMatAutocompleteMissingPanelError(): Error {
'[attr.autocomplete]': 'autocompleteAttribute',
'[attr.role]': 'autocompleteDisabled ? null : "combobox"',
'[attr.aria-autocomplete]': 'autocompleteDisabled ? null : "list"',
'[attr.aria-activedescendant]': 'activeOption?.id',
'[attr.aria-activedescendant]': '(panelOpen && activeOption) ? activeOption.id : null',
'[attr.aria-expanded]': 'autocompleteDisabled ? null : panelOpen.toString()',
'[attr.aria-owns]': '(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id',
// Note: we use `focusin`, as opposed to `focus`, in order to open the panel
+23
View File
@@ -1644,6 +1644,29 @@ describe('MatAutocomplete', () => {
.toContain('mat-active', 'Expected first option to be highlighted.');
}));
it('should remove aria-activedescendant when panel is closed with autoActiveFirstOption',
fakeAsync(() => {
const input: HTMLElement = fixture.nativeElement.querySelector('input');
expect(input.hasAttribute('aria-activedescendant'))
.toBe(false, 'Expected no active descendant on init.');
fixture.componentInstance.trigger.autocomplete.autoActiveFirstOption = true;
fixture.componentInstance.trigger.openPanel();
fixture.detectChanges();
zone.simulateZoneExit();
fixture.detectChanges();
expect(input.getAttribute('aria-activedescendant'))
.toBeTruthy('Expected active descendant while open.');
fixture.componentInstance.trigger.closePanel();
fixture.detectChanges();
expect(input.hasAttribute('aria-activedescendant'))
.toBe(false, 'Expected no active descendant when closed.');
}));
it('should be able to configure preselecting the first option globally', fakeAsync(() => {
overlayContainer.ngOnDestroy();
fixture.destroy();