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