Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/material/menu/menu-trigger-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ export abstract class MatMenuTriggerBase implements OnDestroy {
this._parentMaterialMenu.closed.emit(reason);
}
});
} else {
this._destroyMenu();
}

this._menuItemInstance?._setTriggersSubmenu(this._triggersSubmenu());
Expand Down
16 changes: 15 additions & 1 deletion src/material/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('MatMenu', () => {
window.scroll(0, 0);
});

it('should aria-controls the menu panel', () => {
it('should set aria-controls on the menu panel', () => {
const fixture = TestBed.createComponent(SimpleMenu);
fixture.detectChanges();
fixture.componentInstance.trigger.openMenu();
Expand Down Expand Up @@ -1149,6 +1149,20 @@ describe('MatMenu', () => {
expect(Math.floor(panelRect.bottom)).toBe(viewportHeight);
});

it('should close the menu when it is cleared from the trigger', async () => {
const fixture = TestBed.createComponent(SimpleMenu);
fixture.detectChanges();
fixture.componentInstance.trigger.openMenu();
fixture.detectChanges();
await wait(200);
expect(overlayContainerElement.querySelector('.mat-mdc-menu-panel')).toBeTruthy();

fixture.componentInstance.trigger.menu = null;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(overlayContainerElement.querySelector('.mat-mdc-menu-panel')).toBeFalsy();
});

describe('lazy rendering', () => {
it('should be able to render the menu content lazily', () => {
const fixture = TestBed.createComponent(SimpleLazyMenu);
Expand Down
Loading