@@ -196,6 +196,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
196196 }
197197
198198 const overlayRef = this . _createOverlay ( ) ;
199+ this . _setPosition ( overlayRef . getConfig ( ) . positionStrategy as FlexibleConnectedPositionStrategy ) ;
199200 overlayRef . attach ( this . _portal ) ;
200201
201202 if ( this . menu . lazyContent ) {
@@ -350,7 +351,9 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
350351 */
351352 private _getOverlayConfig ( ) : OverlayConfig {
352353 return new OverlayConfig ( {
353- positionStrategy : this . _getPosition ( ) ,
354+ positionStrategy : this . _overlay . position ( )
355+ . flexibleConnectedTo ( this . _element )
356+ . withTransformOriginOn ( '.mat-menu-panel' ) ,
354357 hasBackdrop : this . menu . hasBackdrop == null ? ! this . triggersSubmenu ( ) : this . menu . hasBackdrop ,
355358 backdropClass : this . menu . backdropClass || 'cdk-overlay-transparent-backdrop' ,
356359 scrollStrategy : this . _scrollStrategy ( ) ,
@@ -375,11 +378,11 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
375378 }
376379
377380 /**
378- * This method builds the position strategy for the overlay, so the menu is properly connected
379- * to the trigger.
380- * @returns ConnectedPositionStrategy
381+ * Sets the appropriate positions on a position strategy
382+ * so the overlay connects with the trigger correctly .
383+ * @param positionStrategy Strategy whose position to update.
381384 */
382- private _getPosition ( ) : FlexibleConnectedPositionStrategy {
385+ private _setPosition ( positionStrategy : FlexibleConnectedPositionStrategy ) {
383386 let [ originX , originFallbackX ] : HorizontalConnectionPos [ ] =
384387 this . menu . xPosition === 'before' ? [ 'end' , 'start' ] : [ 'start' , 'end' ] ;
385388
@@ -401,27 +404,24 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
401404 originFallbackY = overlayFallbackY === 'top' ? 'bottom' : 'top' ;
402405 }
403406
404- return this . _overlay . position ( )
405- . flexibleConnectedTo ( this . _element )
406- . withTransformOriginOn ( '.mat-menu-panel' )
407- . withPositions ( [
408- { originX, originY, overlayX, overlayY, offsetY} ,
409- { originX : originFallbackX , originY, overlayX : overlayFallbackX , overlayY, offsetY} ,
410- {
411- originX,
412- originY : originFallbackY ,
413- overlayX,
414- overlayY : overlayFallbackY ,
415- offsetY : - offsetY
416- } ,
417- {
418- originX : originFallbackX ,
419- originY : originFallbackY ,
420- overlayX : overlayFallbackX ,
421- overlayY : overlayFallbackY ,
422- offsetY : - offsetY
423- }
424- ] ) ;
407+ positionStrategy . withPositions ( [
408+ { originX, originY, overlayX, overlayY, offsetY} ,
409+ { originX : originFallbackX , originY, overlayX : overlayFallbackX , overlayY, offsetY} ,
410+ {
411+ originX,
412+ originY : originFallbackY ,
413+ overlayX,
414+ overlayY : overlayFallbackY ,
415+ offsetY : - offsetY
416+ } ,
417+ {
418+ originX : originFallbackX ,
419+ originY : originFallbackY ,
420+ overlayX : overlayFallbackX ,
421+ overlayY : overlayFallbackY ,
422+ offsetY : - offsetY
423+ }
424+ ] ) ;
425425 }
426426
427427 /** Cleans up the active subscriptions. */
0 commit comments