@@ -15,9 +15,11 @@ import {
1515import { Direction , Directionality } from '@angular/cdk/bidi' ;
1616import { ENTER , LEFT_ARROW , RIGHT_ARROW , SPACE } from '@angular/cdk/keycodes' ;
1717import {
18+ createFlexibleConnectedPositionStrategy ,
19+ createOverlayRef ,
20+ createRepositionScrollStrategy ,
1821 FlexibleConnectedPositionStrategy ,
1922 HorizontalConnectionPos ,
20- Overlay ,
2123 OverlayConfig ,
2224 OverlayRef ,
2325 ScrollStrategy ,
@@ -32,6 +34,7 @@ import {
3234 EventEmitter ,
3335 inject ,
3436 InjectionToken ,
37+ Injector ,
3538 Input ,
3639 NgZone ,
3740 OnDestroy ,
@@ -54,8 +57,8 @@ export const MAT_MENU_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>
5457 {
5558 providedIn : 'root' ,
5659 factory : ( ) => {
57- const overlay = inject ( Overlay ) ;
58- return ( ) => overlay . scrollStrategies . reposition ( ) ;
60+ const injector = inject ( Injector ) ;
61+ return ( ) => createRepositionScrollStrategy ( injector ) ;
5962 } ,
6063 } ,
6164) ;
@@ -65,8 +68,9 @@ export const MAT_MENU_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>
6568 * @deprecated No longer used, will be removed.
6669 * @breaking -change 21.0.0
6770 */
68- export function MAT_MENU_SCROLL_STRATEGY_FACTORY ( overlay : Overlay ) : ( ) => ScrollStrategy {
69- return ( ) => overlay . scrollStrategies . reposition ( ) ;
71+ export function MAT_MENU_SCROLL_STRATEGY_FACTORY ( _overlay : unknown ) : ( ) => ScrollStrategy {
72+ const injector = inject ( Injector ) ;
73+ return ( ) => createRepositionScrollStrategy ( injector ) ;
7074}
7175
7276/**
@@ -76,13 +80,10 @@ export function MAT_MENU_SCROLL_STRATEGY_FACTORY(overlay: Overlay): () => Scroll
7680 */
7781export const MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER = {
7882 provide : MAT_MENU_SCROLL_STRATEGY ,
79- deps : [ Overlay ] ,
83+ deps : [ ] as any [ ] ,
8084 useFactory : MAT_MENU_SCROLL_STRATEGY_FACTORY ,
8185} ;
8286
83- /** Options for binding a passive event listener. */
84- const passiveEventListenerOptions = { passive : true } ;
85-
8687/**
8788 * Default top padding of the menu panel.
8889 * @deprecated No longer being used. Will be removed.
@@ -108,13 +109,13 @@ const PANELS_TO_TRIGGERS = new WeakMap<MatMenuPanel, MatMenuTrigger>();
108109 exportAs : 'matMenuTrigger' ,
109110} )
110111export class MatMenuTrigger implements AfterContentInit , OnDestroy {
111- private _overlay = inject ( Overlay ) ;
112112 private _element = inject < ElementRef < HTMLElement > > ( ElementRef ) ;
113113 private _viewContainerRef = inject ( ViewContainerRef ) ;
114114 private _menuItemInstance = inject ( MatMenuItem , { optional : true , self : true } ) ! ;
115115 private _dir = inject ( Directionality , { optional : true } ) ;
116116 private _focusMonitor = inject ( FocusMonitor ) ;
117117 private _ngZone = inject ( NgZone ) ;
118+ private _injector = inject ( Injector ) ;
118119 private _scrollStrategy = inject ( MAT_MENU_SCROLL_STRATEGY ) ;
119120 private _changeDetectorRef = inject ( ChangeDetectorRef ) ;
120121 private _animationsDisabled = _animationsDisabled ( ) ;
@@ -235,7 +236,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
235236 this . _openedBy = 'touch' ;
236237 }
237238 } ,
238- passiveEventListenerOptions ,
239+ { passive : true } ,
239240 ) ;
240241 }
241242
@@ -420,7 +421,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
420421 menu ,
421422 config . positionStrategy as FlexibleConnectedPositionStrategy ,
422423 ) ;
423- this . _overlayRef = this . _overlay . create ( config ) ;
424+ this . _overlayRef = createOverlayRef ( this . _injector , config ) ;
424425 this . _overlayRef . keydownEvents ( ) . subscribe ( event => {
425426 if ( this . menu instanceof MatMenu ) {
426427 this . menu . _handleKeydown ( event ) ;
@@ -437,9 +438,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
437438 */
438439 private _getOverlayConfig ( menu : MatMenuPanel ) : OverlayConfig {
439440 return new OverlayConfig ( {
440- positionStrategy : this . _overlay
441- . position ( )
442- . flexibleConnectedTo ( this . _element )
441+ positionStrategy : createFlexibleConnectedPositionStrategy ( this . _injector , this . _element )
443442 . withLockedPosition ( )
444443 . withGrowAfterOpen ( )
445444 . withTransformOriginOn ( '.mat-menu-panel, .mat-mdc-menu-panel' ) ,
0 commit comments