File tree 2 files changed +21
-1
lines changed
2 files changed +21
-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,24 @@ 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
+ const { top : beforeTop , left : beforeLeft } = panel . getBoundingClientRect ( ) ;
309
+
310
+ fixture . componentInstance . trigger . closeMenu ( ) ;
311
+ fixture . componentInstance . xPosition = 'after' ;
312
+ fixture . componentInstance . yPosition = 'below' ;
313
+ fixture . detectChanges ( ) ;
314
+ tick ( 500 ) ;
315
+
316
+ fixture . componentInstance . trigger . openMenu ( ) ;
317
+ fixture . detectChanges ( ) ;
318
+
319
+ const newPanel = overlayContainerElement . querySelector ( '.mat-menu-panel' ) as HTMLElement ;
320
+ const { top : afterTop , left : afterLeft } = newPanel . getBoundingClientRect ( ) ;
321
+
322
+ expect ( beforeLeft ) . toBeLessThan ( afterLeft ) ;
323
+ expect ( beforeTop ) . toBeLessThan ( afterTop ) ;
324
+ } ) ) ;
307
325
} ) ;
308
326
309
327
describe ( 'fallback positions' , ( ) => {
You can’t perform that action at this time.
0 commit comments