Skip to content

Commit f3065cc

Browse files
crisbetojelbourn
authored andcommittedDec 20, 2018
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.
1 parent 0398d53 commit f3065cc

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
 

‎src/lib/autocomplete/autocomplete-trigger.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function getMatAutocompleteMissingPanelError(): Error {
102102
'[attr.autocomplete]': 'autocompleteAttribute',
103103
'[attr.role]': 'autocompleteDisabled ? null : "combobox"',
104104
'[attr.aria-autocomplete]': 'autocompleteDisabled ? null : "list"',
105-
'[attr.aria-activedescendant]': 'activeOption?.id',
105+
'[attr.aria-activedescendant]': '(panelOpen && activeOption) ? activeOption.id : null',
106106
'[attr.aria-expanded]': 'autocompleteDisabled ? null : panelOpen.toString()',
107107
'[attr.aria-owns]': '(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id',
108108
// Note: we use `focusin`, as opposed to `focus`, in order to open the panel

‎src/lib/autocomplete/autocomplete.spec.ts

+23
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,29 @@ describe('MatAutocomplete', () => {
16441644
.toContain('mat-active', 'Expected first option to be highlighted.');
16451645
}));
16461646

1647+
it('should remove aria-activedescendant when panel is closed with autoActiveFirstOption',
1648+
fakeAsync(() => {
1649+
const input: HTMLElement = fixture.nativeElement.querySelector('input');
1650+
1651+
expect(input.hasAttribute('aria-activedescendant'))
1652+
.toBe(false, 'Expected no active descendant on init.');
1653+
1654+
fixture.componentInstance.trigger.autocomplete.autoActiveFirstOption = true;
1655+
fixture.componentInstance.trigger.openPanel();
1656+
fixture.detectChanges();
1657+
zone.simulateZoneExit();
1658+
fixture.detectChanges();
1659+
1660+
expect(input.getAttribute('aria-activedescendant'))
1661+
.toBeTruthy('Expected active descendant while open.');
1662+
1663+
fixture.componentInstance.trigger.closePanel();
1664+
fixture.detectChanges();
1665+
1666+
expect(input.hasAttribute('aria-activedescendant'))
1667+
.toBe(false, 'Expected no active descendant when closed.');
1668+
}));
1669+
16471670
it('should be able to configure preselecting the first option globally', fakeAsync(() => {
16481671
overlayContainer.ngOnDestroy();
16491672
fixture.destroy();

0 commit comments

Comments
 (0)
Please sign in to comment.