mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Jeremy Elbourn
parent
0398d53bae
commit
f3065cccaf
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user