File tree Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ import {throwMatMenuInvalidPositionX, throwMatMenuInvalidPositionY} from './menu
37
37
import { MatMenuItem } from './menu-item' ;
38
38
import { MAT_MENU_PANEL , MatMenuPanel } from './menu-panel' ;
39
39
import { MenuPositionX , MenuPositionY } from './menu-positions' ;
40
+ import { AnimationEvent } from '@angular/animations' ;
40
41
41
42
42
43
/** Default `mat-menu` options that can be overridden. */
Original file line number Diff line number Diff line change @@ -235,7 +235,6 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
235
235
236
236
const menu = this . menu ;
237
237
238
- this . _resetMenu ( ) ;
239
238
this . _closeSubscription . unsubscribe ( ) ;
240
239
this . _overlayRef . detach ( ) ;
241
240
@@ -245,11 +244,20 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
245
244
if ( menu . lazyContent ) {
246
245
// Wait for the exit animation to finish before detaching the content.
247
246
menu . _animationDone
248
- . pipe ( take ( 1 ) )
249
- . subscribe ( ( ) => menu . lazyContent ! . detach ( ) ) ;
247
+ . pipe ( filter ( event => event . toState === 'void' ) , take ( 1 ) )
248
+ . subscribe ( ( ) => {
249
+ menu . lazyContent ! . detach ( ) ;
250
+ this . _resetMenu ( ) ;
251
+ } ) ;
252
+ } else {
253
+ this . _resetMenu ( ) ;
254
+ }
255
+ } else {
256
+ this . _resetMenu ( ) ;
257
+
258
+ if ( menu . lazyContent ) {
259
+ menu . lazyContent . detach ( ) ;
250
260
}
251
- } else if ( menu . lazyContent ) {
252
- menu . lazyContent . detach ( ) ;
253
261
}
254
262
}
255
263
Original file line number Diff line number Diff line change @@ -418,6 +418,31 @@ describe('MatMenu', () => {
418
418
expect ( fixture . componentInstance . items . length ) . toBe ( 0 ) ;
419
419
} ) ) ;
420
420
421
+ it ( 'should wait for the close animation to finish before considering the panel as closed' ,
422
+ fakeAsync ( ( ) => {
423
+ const fixture = createComponent ( SimpleLazyMenu ) ;
424
+ fixture . detectChanges ( ) ;
425
+ const trigger = fixture . componentInstance . trigger ;
426
+
427
+ expect ( trigger . menuOpen ) . toBe ( false , 'Expected menu to start off closed' ) ;
428
+
429
+ trigger . openMenu ( ) ;
430
+ fixture . detectChanges ( ) ;
431
+ tick ( 500 ) ;
432
+
433
+ expect ( trigger . menuOpen ) . toBe ( true , 'Expected menu to be open' ) ;
434
+
435
+ trigger . closeMenu ( ) ;
436
+ fixture . detectChanges ( ) ;
437
+
438
+ expect ( trigger . menuOpen )
439
+ . toBe ( true , 'Expected menu to be considered open while the close animation is running' ) ;
440
+ tick ( 500 ) ;
441
+ fixture . detectChanges ( ) ;
442
+
443
+ expect ( trigger . menuOpen ) . toBe ( false , 'Expected menu to be closed' ) ;
444
+ } ) ) ;
445
+
421
446
it ( 'should focus the first menu item when opening a lazy menu via keyboard' , fakeAsync ( ( ) => {
422
447
let zone : MockNgZone ;
423
448
let fixture = createComponent ( SimpleLazyMenu , [ {
You can’t perform that action at this time.
0 commit comments