mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(menu): close child menus when parent is closed programmatically (#6329)
Fixes the child menus not closing themselves when a parent menu is closed via `closeMenu`.
This commit is contained in:
committed by
Andrew Seguin
parent
9bdd228618
commit
66b1ff52b0
@@ -214,9 +214,10 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
|
||||
/** Closes the menu. */
|
||||
closeMenu(): void {
|
||||
if (this._overlayRef && this.menuOpen) {
|
||||
this._resetMenu();
|
||||
this._overlayRef.detach();
|
||||
this._closeSubscription.unsubscribe();
|
||||
this._resetMenu();
|
||||
this.menu.close.emit();
|
||||
|
||||
if (this.menu instanceof MdMenu) {
|
||||
this.menu._resetAnimation();
|
||||
|
||||
@@ -961,6 +961,28 @@ describe('MdMenu', () => {
|
||||
.not.toContain('mat-elevation-z3', 'Expected no stacked elevation.');
|
||||
});
|
||||
|
||||
it('should close all of the menus when the root is closed programmatically', () => {
|
||||
compileTestComponent();
|
||||
instance.rootTrigger.openMenu();
|
||||
fixture.detectChanges();
|
||||
|
||||
instance.levelOneTrigger.openMenu();
|
||||
fixture.detectChanges();
|
||||
|
||||
instance.levelTwoTrigger.openMenu();
|
||||
fixture.detectChanges();
|
||||
|
||||
const menus = overlay.querySelectorAll('.mat-menu-panel');
|
||||
|
||||
expect(menus.length).toBe(3, 'Expected three open menus');
|
||||
|
||||
instance.rootTrigger.closeMenu();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(overlay.querySelectorAll('.mat-menu-panel').length).toBe(0, 'Expected no open menus');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user