Skip to content

Commit

Permalink
fix(menu): close child menus when parent is closed programmatically (#…
Browse files Browse the repository at this point in the history
…6329)

Fixes the child menus not closing themselves when a parent menu is closed via `closeMenu`.
  • Loading branch information
crisbeto authored and andrewseguin committed Aug 15, 2017
1 parent 9bdd228 commit 66b1ff5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/menu/menu-trigger.ts
Expand Up @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions src/lib/menu/menu.spec.ts
Expand Up @@ -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');
});


});

});
Expand Down

0 comments on commit 66b1ff5

Please sign in to comment.