Skip to content
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
1 change: 1 addition & 0 deletions src/lib/menu/menu-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {throwMatMenuInvalidPositionX, throwMatMenuInvalidPositionY} from './menu
import {MatMenuItem} from './menu-item';
import {MAT_MENU_PANEL, MatMenuPanel} from './menu-panel';
import {MenuPositionX, MenuPositionY} from './menu-positions';
import {AnimationEvent} from '@angular/animations';


/** Default `mat-menu` options that can be overridden. */
Expand Down
18 changes: 13 additions & 5 deletions src/lib/menu/menu-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {

const menu = this.menu;

this._resetMenu();
this._closeSubscription.unsubscribe();
this._overlayRef.detach();

Expand All @@ -243,11 +242,20 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
if (menu.lazyContent) {
// Wait for the exit animation to finish before detaching the content.
menu._animationDone
.pipe(take(1))
.subscribe(() => menu.lazyContent!.detach());
.pipe(filter(event => event.toState === 'void'), take(1))
.subscribe(() => {
menu.lazyContent!.detach();
this._resetMenu();
});
} else {
this._resetMenu();
}
} else {
this._resetMenu();

if (menu.lazyContent) {
menu.lazyContent.detach();
}
} else if (menu.lazyContent) {
menu.lazyContent.detach();
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/lib/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,31 @@ describe('MatMenu', () => {
expect(fixture.componentInstance.items.length).toBe(0);
}));

it('should wait for the close animation to finish before considering the panel as closed',
fakeAsync(() => {
const fixture = createComponent(SimpleLazyMenu);
fixture.detectChanges();
const trigger = fixture.componentInstance.trigger;

expect(trigger.menuOpen).toBe(false, 'Expected menu to start off closed');

trigger.openMenu();
fixture.detectChanges();
tick(500);

expect(trigger.menuOpen).toBe(true, 'Expected menu to be open');

trigger.closeMenu();
fixture.detectChanges();

expect(trigger.menuOpen)
.toBe(true, 'Expected menu to be considered open while the close animation is running');
tick(500);
fixture.detectChanges();

expect(trigger.menuOpen).toBe(false, 'Expected menu to be closed');
}));

it('should focus the first menu item when opening a lazy menu via keyboard', fakeAsync(() => {
let zone: MockNgZone;
let fixture = createComponent(SimpleLazyMenu, [{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component} from '@angular/core';
import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';

/**
Expand All @@ -9,7 +9,7 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms';
templateUrl: 'stepper-vertical-example.html',
styleUrls: ['stepper-vertical-example.css']
})
export class StepperVerticalExample {
export class StepperVerticalExample implements OnInit {
isLinear = false;
firstFormGroup: FormGroup;
secondFormGroup: FormGroup;
Expand Down