Skip to content

Commit 3ea7641

Browse files
crisbetoandrewseguin
authored andcommitted
fix(material/autocomplete): use narrow value for aria-haspopup (#15361)
[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)
1 parent c9a1547 commit 3ea7641

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/material-experimental/mdc-autocomplete/autocomplete-trigger.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const MAT_AUTOCOMPLETE_VALUE_ACCESSOR: any = {
3434
'[attr.aria-activedescendant]': '(panelOpen && activeOption) ? activeOption.id : null',
3535
'[attr.aria-expanded]': 'autocompleteDisabled ? null : panelOpen.toString()',
3636
'[attr.aria-owns]': '(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id',
37-
'[attr.aria-haspopup]': '!autocompleteDisabled',
37+
'[attr.aria-haspopup]': 'autocompleteDisabled ? null : "listbox"',
3838
// Note: we use `focusin`, as opposed to `focus`, in order to open the panel
3939
// a little earlier. This avoids issues where IE delays the focusing of the input.
4040
'(focusin)': '_handleFocus()',

src/material-experimental/mdc-autocomplete/autocomplete.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,12 @@ describe('MDC-based MatAutocomplete', () => {
562562
});
563563

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

567567
fixture.componentInstance.autocompleteDisabled = true;
568568
fixture.detectChanges();
569569

570-
expect(input.getAttribute('aria-haspopup')).toBe('false');
570+
expect(input.hasAttribute('aria-haspopup')).toBe(false);
571571
});
572572
});
573573

src/material/autocomplete/autocomplete-trigger.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ export abstract class _MatAutocompleteTriggerBase
792792
'[attr.aria-activedescendant]': '(panelOpen && activeOption) ? activeOption.id : null',
793793
'[attr.aria-expanded]': 'autocompleteDisabled ? null : panelOpen.toString()',
794794
'[attr.aria-owns]': '(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id',
795-
'[attr.aria-haspopup]': '!autocompleteDisabled',
795+
'[attr.aria-haspopup]': 'autocompleteDisabled ? null : "listbox"',
796796
// Note: we use `focusin`, as opposed to `focus`, in order to open the panel
797797
// a little earlier. This avoids issues where IE delays the focusing of the input.
798798
'(focusin)': '_handleFocus()',

src/material/autocomplete/autocomplete.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,12 @@ describe('MatAutocomplete', () => {
559559
});
560560

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

564564
fixture.componentInstance.autocompleteDisabled = true;
565565
fixture.detectChanges();
566566

567-
expect(input.getAttribute('aria-haspopup')).toBe('false');
567+
expect(input.hasAttribute('aria-haspopup')).toBe(false);
568568
});
569569
});
570570

0 commit comments

Comments
 (0)