File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 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 {
308308 * OverlayRef so that it can be attached to the DOM when openMenu is called.
309309 */
310310 private _createOverlay ( ) : OverlayRef {
311- if ( ! this . _overlayRef ) {
311+ if ( this . _overlayRef ) {
312+ this . _overlayRef . getConfig ( ) . positionStrategy = this . _getPosition ( ) ;
313+ } else {
312314 this . _portal = new TemplatePortal ( this . menu . templateRef , this . _viewContainerRef ) ;
313315 const config = this . _getOverlayConfig ( ) ;
314316 this . _subscribeToPositions ( config . positionStrategy as ConnectedPositionStrategy ) ;
Original file line number Diff line number Diff line change @@ -304,6 +304,24 @@ describe('MatMenu', () => {
304304 expect ( panel . classList ) . toContain ( 'mat-menu-after' ) ;
305305 } ) ;
306306
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+ } ) ) ;
307325 } ) ;
308326
309327 describe ( 'fallback positions' , ( ) => {
You can’t perform that action at this time.
0 commit comments