Skip to content

Commit 4864763

Browse files
committed
fix(material/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 8ba7148 commit 4864763

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
@@ -132,6 +132,14 @@ describe('MDC-based MatMenu', () => {
132132
expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeFalsy();
133133
}));
134134

135+
it('should set the correct aria-haspopup value on the trigger element', fakeAsync(() => {
136+
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
137+
fixture.detectChanges();
138+
const triggerElement = fixture.componentInstance.triggerEl.nativeElement;
139+
140+
expect(triggerElement.getAttribute('aria-haspopup')).toBe('menu');
141+
}));
142+
135143
it('should be able to remove the backdrop on repeat openings', fakeAsync(() => {
136144
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
137145
fixture.detectChanges();

src/material/menu/menu-trigger.ts

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

src/material/menu/menu.spec.ts

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

136+
it('should set the correct aria-haspopup value on the trigger element', fakeAsync(() => {
137+
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
138+
fixture.detectChanges();
139+
const triggerElement = fixture.componentInstance.triggerEl.nativeElement;
140+
141+
expect(triggerElement.getAttribute('aria-haspopup')).toBe('menu');
142+
}));
143+
136144
it('should be able to remove the backdrop on repeat openings', fakeAsync(() => {
137145
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
138146
fixture.detectChanges();

0 commit comments

Comments
 (0)