@@ -11,6 +11,7 @@ import {
11
11
Directive ,
12
12
ElementRef ,
13
13
inject ,
14
+ Injector ,
14
15
NgZone ,
15
16
OnChanges ,
16
17
OnDestroy ,
@@ -21,8 +22,9 @@ import {InputModalityDetector} from '../a11y';
21
22
import { Directionality } from '../bidi' ;
22
23
import {
23
24
ConnectedPosition ,
25
+ createFlexibleConnectedPositionStrategy ,
26
+ createOverlayRef ,
24
27
FlexibleConnectedPositionStrategy ,
25
- Overlay ,
26
28
OverlayConfig ,
27
29
STANDARD_DROPDOWN_ADJACENT_POSITIONS ,
28
30
STANDARD_DROPDOWN_BELOW_POSITIONS ,
@@ -76,12 +78,12 @@ import {eventDispatchesNativeClick} from './event-detection';
76
78
} )
77
79
export class CdkMenuTrigger extends CdkMenuTriggerBase implements OnChanges , OnDestroy {
78
80
private readonly _elementRef : ElementRef < HTMLElement > = inject ( ElementRef ) ;
79
- private readonly _overlay = inject ( Overlay ) ;
80
81
private readonly _ngZone = inject ( NgZone ) ;
81
82
private readonly _changeDetectorRef = inject ( ChangeDetectorRef ) ;
82
83
private readonly _inputModalityDetector = inject ( InputModalityDetector ) ;
83
84
private readonly _directionality = inject ( Directionality , { optional : true } ) ;
84
85
private readonly _renderer = inject ( Renderer2 ) ;
86
+ private readonly _injector = inject ( Injector ) ;
85
87
private _cleanupMouseenter : ( ) => void ;
86
88
87
89
/** The parent menu this trigger belongs to. */
@@ -110,7 +112,8 @@ export class CdkMenuTrigger extends CdkMenuTriggerBase implements OnChanges, OnD
110
112
if ( ! this . isOpen ( ) && this . menuTemplateRef != null ) {
111
113
this . opened . next ( ) ;
112
114
113
- this . overlayRef = this . overlayRef || this . _overlay . create ( this . _getOverlayConfig ( ) ) ;
115
+ this . overlayRef =
116
+ this . overlayRef || createOverlayRef ( this . _injector , this . _getOverlayConfig ( ) ) ;
114
117
this . overlayRef . attach ( this . getMenuContentPortal ( ) ) ;
115
118
this . _changeDetectorRef . markForCheck ( ) ;
116
119
this . _subscribeToOutsideClicks ( ) ;
@@ -272,9 +275,7 @@ export class CdkMenuTrigger extends CdkMenuTriggerBase implements OnChanges, OnD
272
275
273
276
/** Build the position strategy for the overlay which specifies where to place the menu. */
274
277
private _getOverlayPositionStrategy ( ) : FlexibleConnectedPositionStrategy {
275
- return this . _overlay
276
- . position ( )
277
- . flexibleConnectedTo ( this . _elementRef )
278
+ return createFlexibleConnectedPositionStrategy ( this . _injector , this . _elementRef )
278
279
. withLockedPosition ( )
279
280
. withFlexibleDimensions ( false )
280
281
. withPositions ( this . _getOverlayPositions ( ) ) ;
0 commit comments