File tree 2 files changed +23
-1
lines changed
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -308,7 +308,9 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
308
308
* OverlayRef so that it can be attached to the DOM when openMenu is called.
309
309
*/
310
310
private _createOverlay ( ) : OverlayRef {
311
- if ( ! this . _overlayRef ) {
311
+ if ( this . _overlayRef ) {
312
+ this . _overlayRef . getConfig ( ) . positionStrategy = this . _getPosition ( ) ;
313
+ } else {
312
314
this . _portal = new TemplatePortal ( this . menu . templateRef , this . _viewContainerRef ) ;
313
315
const config = this . _getOverlayConfig ( ) ;
314
316
this . _subscribeToPositions ( config . positionStrategy as ConnectedPositionStrategy ) ;
Original file line number Diff line number Diff line change @@ -304,6 +304,26 @@ describe('MatMenu', () => {
304
304
expect ( panel . classList ) . toContain ( 'mat-menu-after' ) ;
305
305
} ) ;
306
306
307
+ it ( 'should update menu position on every open' , fakeAsync ( ( ) => {
308
+ debugger ;
309
+
310
+ const { top : beforeTop , left : beforeLeft } = panel . getBoundingClientRect ( ) ;
311
+
312
+ fixture . componentInstance . trigger . closeMenu ( ) ;
313
+ fixture . componentInstance . xPosition = 'after' ;
314
+ fixture . componentInstance . yPosition = 'below' ;
315
+ fixture . detectChanges ( ) ;
316
+ tick ( 500 ) ;
317
+
318
+ fixture . componentInstance . trigger . openMenu ( ) ;
319
+ fixture . detectChanges ( ) ;
320
+
321
+ const newPanel = overlayContainerElement . querySelector ( '.mat-menu-panel' ) as HTMLElement ;
322
+ const { top : afterTop , left : afterLeft } = newPanel . getBoundingClientRect ( ) ;
323
+
324
+ expect ( beforeLeft ) . toBeLessThan ( afterLeft ) ;
325
+ expect ( beforeTop ) . toBeLessThan ( afterTop ) ;
326
+ } ) ) ;
307
327
} ) ;
308
328
309
329
describe ( 'fallback positions' , ( ) => {
You can’t perform that action at this time.
0 commit comments