File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 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 {
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,26 @@ describe('MatMenu', () => {
304304 expect ( panel . classList ) . toContain ( 'mat-menu-after' ) ;
305305 } ) ;
306306
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+ } ) ) ;
307327 } ) ;
308328
309329 describe ( 'fallback positions' , ( ) => {
You can’t perform that action at this time.
0 commit comments