@@ -15,9 +15,11 @@ import {
15
15
import { Direction , Directionality } from '@angular/cdk/bidi' ;
16
16
import { ENTER , LEFT_ARROW , RIGHT_ARROW , SPACE } from '@angular/cdk/keycodes' ;
17
17
import {
18
+ createFlexibleConnectedPositionStrategy ,
19
+ createOverlayRef ,
20
+ createRepositionScrollStrategy ,
18
21
FlexibleConnectedPositionStrategy ,
19
22
HorizontalConnectionPos ,
20
- Overlay ,
21
23
OverlayConfig ,
22
24
OverlayRef ,
23
25
ScrollStrategy ,
@@ -32,6 +34,7 @@ import {
32
34
EventEmitter ,
33
35
inject ,
34
36
InjectionToken ,
37
+ Injector ,
35
38
Input ,
36
39
NgZone ,
37
40
OnDestroy ,
@@ -54,8 +57,8 @@ export const MAT_MENU_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>
54
57
{
55
58
providedIn : 'root' ,
56
59
factory : ( ) => {
57
- const overlay = inject ( Overlay ) ;
58
- return ( ) => overlay . scrollStrategies . reposition ( ) ;
60
+ const injector = inject ( Injector ) ;
61
+ return ( ) => createRepositionScrollStrategy ( injector ) ;
59
62
} ,
60
63
} ,
61
64
) ;
@@ -65,8 +68,9 @@ export const MAT_MENU_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>
65
68
* @deprecated No longer used, will be removed.
66
69
* @breaking -change 21.0.0
67
70
*/
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 ) ;
70
74
}
71
75
72
76
/**
@@ -76,13 +80,10 @@ export function MAT_MENU_SCROLL_STRATEGY_FACTORY(overlay: Overlay): () => Scroll
76
80
*/
77
81
export const MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER = {
78
82
provide : MAT_MENU_SCROLL_STRATEGY ,
79
- deps : [ Overlay ] ,
83
+ deps : [ ] as any [ ] ,
80
84
useFactory : MAT_MENU_SCROLL_STRATEGY_FACTORY ,
81
85
} ;
82
86
83
- /** Options for binding a passive event listener. */
84
- const passiveEventListenerOptions = { passive : true } ;
85
-
86
87
/**
87
88
* Default top padding of the menu panel.
88
89
* @deprecated No longer being used. Will be removed.
@@ -108,13 +109,13 @@ const PANELS_TO_TRIGGERS = new WeakMap<MatMenuPanel, MatMenuTrigger>();
108
109
exportAs : 'matMenuTrigger' ,
109
110
} )
110
111
export class MatMenuTrigger implements AfterContentInit , OnDestroy {
111
- private _overlay = inject ( Overlay ) ;
112
112
private _element = inject < ElementRef < HTMLElement > > ( ElementRef ) ;
113
113
private _viewContainerRef = inject ( ViewContainerRef ) ;
114
114
private _menuItemInstance = inject ( MatMenuItem , { optional : true , self : true } ) ! ;
115
115
private _dir = inject ( Directionality , { optional : true } ) ;
116
116
private _focusMonitor = inject ( FocusMonitor ) ;
117
117
private _ngZone = inject ( NgZone ) ;
118
+ private _injector = inject ( Injector ) ;
118
119
private _scrollStrategy = inject ( MAT_MENU_SCROLL_STRATEGY ) ;
119
120
private _changeDetectorRef = inject ( ChangeDetectorRef ) ;
120
121
private _animationsDisabled = _animationsDisabled ( ) ;
@@ -235,7 +236,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
235
236
this . _openedBy = 'touch' ;
236
237
}
237
238
} ,
238
- passiveEventListenerOptions ,
239
+ { passive : true } ,
239
240
) ;
240
241
}
241
242
@@ -420,7 +421,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
420
421
menu ,
421
422
config . positionStrategy as FlexibleConnectedPositionStrategy ,
422
423
) ;
423
- this . _overlayRef = this . _overlay . create ( config ) ;
424
+ this . _overlayRef = createOverlayRef ( this . _injector , config ) ;
424
425
this . _overlayRef . keydownEvents ( ) . subscribe ( event => {
425
426
if ( this . menu instanceof MatMenu ) {
426
427
this . menu . _handleKeydown ( event ) ;
@@ -437,9 +438,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
437
438
*/
438
439
private _getOverlayConfig ( menu : MatMenuPanel ) : OverlayConfig {
439
440
return new OverlayConfig ( {
440
- positionStrategy : this . _overlay
441
- . position ( )
442
- . flexibleConnectedTo ( this . _element )
441
+ positionStrategy : createFlexibleConnectedPositionStrategy ( this . _injector , this . _element )
443
442
. withLockedPosition ( )
444
443
. withGrowAfterOpen ( )
445
444
. withTransformOriginOn ( '.mat-menu-panel, .mat-mdc-menu-panel' ) ,
0 commit comments