Skip to content

Commit f0a0ab1

Browse files
crisbetommalerba
authored andcommitted
fix(autocomplete): remove aria-owns attribute while closed (#12333)
Removes the `aria-owns` attribute from the autocomplete trigger while the panel is closed. Fixes #12332.
1 parent e67fd7b commit f0a0ab1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function getMatAutocompleteMissingPanelError(): Error {
103103
'[attr.aria-autocomplete]': 'autocompleteDisabled ? null : "list"',
104104
'[attr.aria-activedescendant]': 'activeOption?.id',
105105
'[attr.aria-expanded]': 'autocompleteDisabled ? null : panelOpen.toString()',
106-
'[attr.aria-owns]': 'autocompleteDisabled ? null : autocomplete?.id',
106+
'[attr.aria-owns]': '(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id',
107107
// Note: we use `focusin`, as opposed to `focus`, in order to open the panel
108108
// a little earlier. This avoids issues where IE delays the focusing of the input.
109109
'(focusin)': '_handleFocus()',

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,16 @@ describe('MatAutocomplete', () => {
13291329
const panel = fixture.debugElement.query(By.css('.mat-autocomplete-panel')).nativeElement;
13301330

13311331
expect(input.getAttribute('aria-owns'))
1332-
.toEqual(panel.getAttribute('id'), 'Expected aria-owns to match attached autocomplete.');
1332+
.toBe(panel.getAttribute('id'), 'Expected aria-owns to match attached autocomplete.');
1333+
});
1334+
1335+
it('should not set aria-owns while the autocomplete is closed', () => {
1336+
expect(input.getAttribute('aria-owns')).toBeFalsy();
1337+
1338+
fixture.componentInstance.trigger.openPanel();
1339+
fixture.detectChanges();
1340+
1341+
expect(input.getAttribute('aria-owns')).toBeTruthy();
13331342
});
13341343

13351344
it('should restore focus to the input when clicking to select a value', fakeAsync(() => {

0 commit comments

Comments
 (0)