File tree 2 files changed +32
-2
lines changed
2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -226,7 +226,11 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
226
226
this . _checkMenu ( ) ;
227
227
228
228
const overlayRef = this . _createOverlay ( ) ;
229
- this . _setPosition ( overlayRef . getConfig ( ) . positionStrategy as FlexibleConnectedPositionStrategy ) ;
229
+ const overlayConfig = overlayRef . getConfig ( ) ;
230
+
231
+ this . _setPosition ( overlayConfig . positionStrategy as FlexibleConnectedPositionStrategy ) ;
232
+ overlayConfig . hasBackdrop = this . menu . hasBackdrop == null ? ! this . triggersSubmenu ( ) :
233
+ this . menu . hasBackdrop ;
230
234
overlayRef . attach ( this . _getPortal ( ) ) ;
231
235
232
236
if ( this . menu . lazyContent ) {
@@ -394,7 +398,6 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
394
398
. flexibleConnectedTo ( this . _element )
395
399
. withLockedPosition ( )
396
400
. withTransformOriginOn ( '.mat-menu-panel' ) ,
397
- hasBackdrop : this . menu . hasBackdrop == null ? ! this . triggersSubmenu ( ) : this . menu . hasBackdrop ,
398
401
backdropClass : this . menu . backdropClass || 'cdk-overlay-transparent-backdrop' ,
399
402
scrollStrategy : this . _scrollStrategy ( ) ,
400
403
direction : this . _dir
Original file line number Diff line number Diff line change @@ -114,6 +114,33 @@ describe('MatMenu', () => {
114
114
expect ( overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) ) . toBeFalsy ( ) ;
115
115
} ) ) ;
116
116
117
+ it ( 'should be able to remove the backdrop on repeat openings' , fakeAsync ( ( ) => {
118
+ const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
119
+ fixture . detectChanges ( ) ;
120
+
121
+ fixture . componentInstance . trigger . openMenu ( ) ;
122
+ fixture . detectChanges ( ) ;
123
+ tick ( 500 ) ;
124
+
125
+ // Start off with a backdrop.
126
+ expect ( overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) ) . toBeTruthy ( ) ;
127
+
128
+ fixture . componentInstance . trigger . closeMenu ( ) ;
129
+ fixture . detectChanges ( ) ;
130
+ tick ( 500 ) ;
131
+
132
+ // Change `hasBackdrop` after the first open.
133
+ fixture . componentInstance . menu . hasBackdrop = false ;
134
+ fixture . detectChanges ( ) ;
135
+
136
+ // Reopen the menu.
137
+ fixture . componentInstance . trigger . openMenu ( ) ;
138
+ fixture . detectChanges ( ) ;
139
+ tick ( 500 ) ;
140
+
141
+ expect ( overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) ) . toBeFalsy ( ) ;
142
+ } ) ) ;
143
+
117
144
it ( 'should restore focus to the trigger when the menu was opened by keyboard' , fakeAsync ( ( ) => {
118
145
const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
119
146
fixture . detectChanges ( ) ;
You can’t perform that action at this time.
0 commit comments