Skip to content

Commit 0a46528

Browse files
authored
fix(material/menu): use narrower value for aria-haspopup on trigger element (#15219)
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 087089c commit 0a46528

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('MDC-based MatMenu', () => {
9494
fixture.detectChanges();
9595
const triggerElement = fixture.componentInstance.triggerEl.nativeElement;
9696

97-
expect(triggerElement.getAttribute('aria-haspopup')).toBe('true');
97+
expect(triggerElement.getAttribute('aria-haspopup')).toBe('menu');
9898

9999
fixture.componentInstance.trigger.menu = null;
100100
fixture.detectChanges();
@@ -142,6 +142,14 @@ describe('MDC-based MatMenu', () => {
142142
expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeFalsy();
143143
}));
144144

145+
it('should set the correct aria-haspopup value on the trigger element', fakeAsync(() => {
146+
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
147+
fixture.detectChanges();
148+
const triggerElement = fixture.componentInstance.triggerEl.nativeElement;
149+
150+
expect(triggerElement.getAttribute('aria-haspopup')).toBe('menu');
151+
}));
152+
145153
it('should be able to remove the backdrop on repeat openings', fakeAsync(() => {
146154
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
147155
fixture.detectChanges();

src/material/menu/menu-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const passiveEventListenerOptions = normalizePassiveListenerOptions({passive: tr
7575

7676
@Directive({
7777
host: {
78-
'[attr.aria-haspopup]': 'menu ? true : null',
78+
'[attr.aria-haspopup]': 'menu ? "menu" : null',
7979
'[attr.aria-expanded]': 'menuOpen || null',
8080
'[attr.aria-controls]': 'menuOpen ? menu.panelId : null',
8181
'(click)': '_handleClick($event)',

src/material/menu/menu.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('MatMenu', () => {
9494
fixture.detectChanges();
9595
const triggerElement = fixture.componentInstance.triggerEl.nativeElement;
9696

97-
expect(triggerElement.getAttribute('aria-haspopup')).toBe('true');
97+
expect(triggerElement.getAttribute('aria-haspopup')).toBe('menu');
9898

9999
fixture.componentInstance.trigger.menu = null;
100100
fixture.detectChanges();
@@ -142,6 +142,14 @@ describe('MatMenu', () => {
142142
expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeFalsy();
143143
}));
144144

145+
it('should set the correct aria-haspopup value on the trigger element', fakeAsync(() => {
146+
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
147+
fixture.detectChanges();
148+
const triggerElement = fixture.componentInstance.triggerEl.nativeElement;
149+
150+
expect(triggerElement.getAttribute('aria-haspopup')).toBe('menu');
151+
}));
152+
145153
it('should be able to remove the backdrop on repeat openings', fakeAsync(() => {
146154
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
147155
fixture.detectChanges();

0 commit comments

Comments
 (0)