Skip to content

Commit 3dbaf4e

Browse files
committed
fix(autocomplete): use narrow value for aria-haspopup
[Based on the spec](https://www.w3.org/TR/wai-aria-1.1/#aria-haspopup), `aria-haspopup` can be set to indicate what kind of popup the element has. These changes update the autocomplete one to show that it opens a listbox.
1 parent ae41a0a commit 3dbaf4e

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function getMatAutocompleteMissingPanelError(): Error {
105105
'[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',
108-
'[attr.aria-haspopup]': '!autocompleteDisabled',
108+
'[attr.aria-haspopup]': 'autocompleteDisabled ? null : "listbox"',
109109
// Note: we use `focusin`, as opposed to `focus`, in order to open the panel
110110
// a little earlier. This avoids issues where IE delays the focusing of the input.
111111
'(focusin)': '_handleFocus()',

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,12 @@ describe('MatAutocomplete', () => {
483483
});
484484

485485
it('should set aria-haspopup depending on whether the autocomplete is disabled', () => {
486-
expect(input.getAttribute('aria-haspopup')).toBe('true');
486+
expect(input.getAttribute('aria-haspopup')).toBe('listbox');
487487

488488
fixture.componentInstance.autocompleteDisabled = true;
489489
fixture.detectChanges();
490490

491-
expect(input.getAttribute('aria-haspopup')).toBe('false');
491+
expect(input.hasAttribute('aria-haspopup')).toBe(false);
492492
});
493493

494494
});

0 commit comments

Comments
 (0)