Skip to content

Commit f20a2aa

Browse files
committed
fix(menu): use narrower value for aria-haspopup on trigger element
Currently we set `aria-haspopup` correctly on the menu trigger, however [according to the spec](https://www.w3.org/TR/wai-aria-1.1/#aria-haspopup) we can narrow the value down so that it indicates what kind of popup will be opened.
1 parent 093d007 commit f20a2aa

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ describe('MDC-based MatMenu', () => {
122122
expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeFalsy();
123123
}));
124124

125+
it('should set the correct aria-haspopup value on the trigger element', fakeAsync(() => {
126+
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
127+
fixture.detectChanges();
128+
const triggerElement = fixture.componentInstance.triggerEl.nativeElement;
129+
130+
expect(triggerElement.getAttribute('aria-haspopup')).toBe('menu');
131+
}));
132+
125133
it('should be able to remove the backdrop on repeat openings', fakeAsync(() => {
126134
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
127135
fixture.detectChanges();

src/material/menu/menu-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const passiveEventListenerOptions = normalizePassiveListenerOptions({passive: tr
7474
selector: `[mat-menu-trigger-for], [matMenuTriggerFor]`,
7575
host: {
7676
'class': 'mat-menu-trigger',
77-
'aria-haspopup': 'true',
77+
'aria-haspopup': 'menu',
7878
'[attr.aria-expanded]': 'menuOpen || null',
7979
'[attr.aria-controls]': 'menuOpen ? menu.panelId : null',
8080
'(mousedown)': '_handleMousedown($event)',

src/material/menu/menu.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ describe('MatMenu', () => {
124124
expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeFalsy();
125125
}));
126126

127+
it('should set the correct aria-haspopup value on the trigger element', fakeAsync(() => {
128+
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
129+
fixture.detectChanges();
130+
const triggerElement = fixture.componentInstance.triggerEl.nativeElement;
131+
132+
expect(triggerElement.getAttribute('aria-haspopup')).toBe('menu');
133+
}));
134+
127135
it('should be able to remove the backdrop on repeat openings', fakeAsync(() => {
128136
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
129137
fixture.detectChanges();

0 commit comments

Comments
 (0)