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:
Kristiyan Kostadinov
2017-08-15 23:53:18 +02:00
committed by Andrew Seguin
parent 9bdd228618
commit 66b1ff52b0
2 changed files with 24 additions and 1 deletions
+2 -1
View File
@@ -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();
+22
View File
@@ -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');
});
});
});