Skip to content

Commit fc9ad67

Browse files
committed
fix(material/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 71b7b15 commit fc9ad67

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,12 @@ describe('MDC-based MatAutocomplete', () => {
508508
});
509509

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

513513
fixture.componentInstance.autocompleteDisabled = true;
514514
fixture.detectChanges();
515515

516-
expect(input.getAttribute('aria-haspopup')).toBe('false');
516+
expect(input.hasAttribute('aria-haspopup')).toBe(false);
517517
});
518518

519519
});

src/material/autocomplete/autocomplete-trigger.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ export abstract class _MatAutocompleteTriggerBase implements ControlValueAccesso
779779
'[attr.aria-activedescendant]': '(panelOpen && activeOption) ? activeOption.id : null',
780780
'[attr.aria-expanded]': 'autocompleteDisabled ? null : panelOpen.toString()',
781781
'[attr.aria-owns]': '(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id',
782-
'[attr.aria-haspopup]': '!autocompleteDisabled',
782+
'[attr.aria-haspopup]': 'autocompleteDisabled ? null : "listbox"',
783783
// Note: we use `focusin`, as opposed to `focus`, in order to open the panel
784784
// a little earlier. This avoids issues where IE delays the focusing of the input.
785785
'(focusin)': '_handleFocus()',

src/material/autocomplete/autocomplete.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,12 @@ describe('MatAutocomplete', () => {
508508
});
509509

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

513513
fixture.componentInstance.autocompleteDisabled = true;
514514
fixture.detectChanges();
515515

516-
expect(input.getAttribute('aria-haspopup')).toBe('false');
516+
expect(input.hasAttribute('aria-haspopup')).toBe(false);
517517
});
518518

519519
});

0 commit comments

Comments
 (0)