fix(autocomplete): set aria-haspopup (#15079)

Based on the [autocomplete example from the a11y guidelines](https://www.w3.org/TR/wai-aria-practices-1.1/examples/combobox/aria1.0pattern/combobox-autocomplete-both.html), adds `aria-haspopup` to the autocomplete trigger input.
This commit is contained in:
Kristiyan Kostadinov
2019-02-07 20:48:02 +01:00
committed by Jeremy Elbourn
parent b10dd043ae
commit 40024703cf
2 changed files with 10 additions and 0 deletions
@@ -105,6 +105,7 @@ export function getMatAutocompleteMissingPanelError(): Error {
'[attr.aria-activedescendant]': '(panelOpen && activeOption) ? activeOption.id : null',
'[attr.aria-expanded]': 'autocompleteDisabled ? null : panelOpen.toString()',
'[attr.aria-owns]': '(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id',
'[attr.aria-haspopup]': '!autocompleteDisabled',
// Note: we use `focusin`, as opposed to `focus`, in order to open the panel
// a little earlier. This avoids issues where IE delays the focusing of the input.
'(focusin)': '_handleFocus()',
@@ -482,6 +482,15 @@ describe('MatAutocomplete', () => {
expect(fixture.componentInstance.stateCtrl.value).toBe('hello');
});
it('should set aria-haspopup depending on whether the autocomplete is disabled', () => {
expect(input.getAttribute('aria-haspopup')).toBe('true');
fixture.componentInstance.autocompleteDisabled = true;
fixture.detectChanges();
expect(input.getAttribute('aria-haspopup')).toBe('false');
});
});
it('should have the correct text direction in RTL', () => {