Skip to content

Commit

Permalink
fix(material/autocomplete): use narrow value for aria-haspopup (#15361)
Browse files Browse the repository at this point in the history
[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.

(cherry picked from commit 7e9916b)
  • Loading branch information
crisbeto authored and andrewseguin committed Feb 23, 2022
1 parent c9a1547 commit 3ea7641
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const MAT_AUTOCOMPLETE_VALUE_ACCESSOR: any = {
'[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',
'[attr.aria-haspopup]': 'autocompleteDisabled ? null : "listbox"',
// 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()',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,12 @@ describe('MDC-based MatAutocomplete', () => {
});

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

fixture.componentInstance.autocompleteDisabled = true;
fixture.detectChanges();

expect(input.getAttribute('aria-haspopup')).toBe('false');
expect(input.hasAttribute('aria-haspopup')).toBe(false);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/material/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ export abstract class _MatAutocompleteTriggerBase
'[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',
'[attr.aria-haspopup]': 'autocompleteDisabled ? null : "listbox"',
// 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()',
Expand Down
4 changes: 2 additions & 2 deletions src/material/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,12 @@ describe('MatAutocomplete', () => {
});

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

fixture.componentInstance.autocompleteDisabled = true;
fixture.detectChanges();

expect(input.getAttribute('aria-haspopup')).toBe('false');
expect(input.hasAttribute('aria-haspopup')).toBe(false);
});
});

Expand Down

0 comments on commit 3ea7641

Please sign in to comment.