Skip to content

fix(material/menu): use narrower value for aria-haspopup on trigger element #15219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/material-experimental/mdc-menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('MDC-based MatMenu', () => {
fixture.detectChanges();
const triggerElement = fixture.componentInstance.triggerEl.nativeElement;

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

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

it('should set the correct aria-haspopup value on the trigger element', fakeAsync(() => {
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
fixture.detectChanges();
const triggerElement = fixture.componentInstance.triggerEl.nativeElement;

expect(triggerElement.getAttribute('aria-haspopup')).toBe('menu');
}));

it('should be able to remove the backdrop on repeat openings', fakeAsync(() => {
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
fixture.detectChanges();
Expand Down
2 changes: 1 addition & 1 deletion src/material/menu/menu-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const passiveEventListenerOptions = normalizePassiveListenerOptions({passive: tr

@Directive({
host: {
'[attr.aria-haspopup]': 'menu ? true : null',
'[attr.aria-haspopup]': 'menu ? "menu" : null',
'[attr.aria-expanded]': 'menuOpen || null',
'[attr.aria-controls]': 'menuOpen ? menu.panelId : null',
'(click)': '_handleClick($event)',
Expand Down
10 changes: 9 additions & 1 deletion src/material/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('MatMenu', () => {
fixture.detectChanges();
const triggerElement = fixture.componentInstance.triggerEl.nativeElement;

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

fixture.componentInstance.trigger.menu = null;
fixture.detectChanges();
Expand Down Expand Up @@ -142,6 +142,14 @@ describe('MatMenu', () => {
expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeFalsy();
}));

it('should set the correct aria-haspopup value on the trigger element', fakeAsync(() => {
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
fixture.detectChanges();
const triggerElement = fixture.componentInstance.triggerEl.nativeElement;

expect(triggerElement.getAttribute('aria-haspopup')).toBe('menu');
}));

it('should be able to remove the backdrop on repeat openings', fakeAsync(() => {
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
fixture.detectChanges();
Expand Down