File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -134,6 +134,8 @@ export abstract class MatMenuTriggerBase implements OnDestroy {
134134 this . _parentMaterialMenu . closed . emit ( reason ) ;
135135 }
136136 } ) ;
137+ } else {
138+ this . _destroyMenu ( ) ;
137139 }
138140
139141 this . _menuItemInstance ?. _setTriggersSubmenu ( this . _triggersSubmenu ( ) ) ;
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ describe('MatMenu', () => {
7676 window . scroll ( 0 , 0 ) ;
7777 } ) ;
7878
79- it ( 'should aria-controls the menu panel' , ( ) => {
79+ it ( 'should set aria-controls on the menu panel' , ( ) => {
8080 const fixture = TestBed . createComponent ( SimpleMenu ) ;
8181 fixture . detectChanges ( ) ;
8282 fixture . componentInstance . trigger . openMenu ( ) ;
@@ -1149,6 +1149,20 @@ describe('MatMenu', () => {
11491149 expect ( Math . floor ( panelRect . bottom ) ) . toBe ( viewportHeight ) ;
11501150 } ) ;
11511151
1152+ it ( 'should close the menu when it is cleared from the trigger' , async ( ) => {
1153+ const fixture = TestBed . createComponent ( SimpleMenu ) ;
1154+ fixture . detectChanges ( ) ;
1155+ fixture . componentInstance . trigger . openMenu ( ) ;
1156+ fixture . detectChanges ( ) ;
1157+ await wait ( 200 ) ;
1158+ expect ( overlayContainerElement . querySelector ( '.mat-mdc-menu-panel' ) ) . toBeTruthy ( ) ;
1159+
1160+ fixture . componentInstance . trigger . menu = null ;
1161+ fixture . changeDetectorRef . markForCheck ( ) ;
1162+ fixture . detectChanges ( ) ;
1163+ expect ( overlayContainerElement . querySelector ( '.mat-mdc-menu-panel' ) ) . toBeFalsy ( ) ;
1164+ } ) ;
1165+
11521166 describe ( 'lazy rendering' , ( ) => {
11531167 it ( 'should be able to render the menu content lazily' , ( ) => {
11541168 const fixture = TestBed . createComponent ( SimpleLazyMenu ) ;
You can’t perform that action at this time.
0 commit comments