@@ -17,6 +17,7 @@ import {
17
17
effect ,
18
18
ElementRef ,
19
19
inject ,
20
+ InjectionToken ,
20
21
Injector ,
21
22
input ,
22
23
InputSignal ,
@@ -41,7 +42,7 @@ import {
41
42
MatOptionParentComponent ,
42
43
} from '@angular/material/core' ;
43
44
import { Directionality } from '@angular/cdk/bidi' ;
44
- import { Overlay , OverlayRef } from '@angular/cdk/overlay' ;
45
+ import { Overlay , OverlayRef , ScrollStrategy } from '@angular/cdk/overlay' ;
45
46
import { TemplatePortal } from '@angular/cdk/portal' ;
46
47
import { _getEventTarget } from '@angular/cdk/platform' ;
47
48
import { ENTER , ESCAPE , hasModifierKey , TAB } from '@angular/cdk/keycodes' ;
@@ -62,6 +63,18 @@ export interface MatTimepickerSelected<D> {
62
63
source : MatTimepicker < D > ;
63
64
}
64
65
66
+ /** Injection token used to configure the behavior of the timepicker dropdown while scrolling. */
67
+ export const MAT_TIMEPICKER_SCROLL_STRATEGY = new InjectionToken < ( ) => ScrollStrategy > (
68
+ 'MAT_TIMEPICKER_SCROLL_STRATEGY' ,
69
+ {
70
+ providedIn : 'root' ,
71
+ factory : ( ) => {
72
+ const overlay = inject ( Overlay ) ;
73
+ return ( ) => overlay . scrollStrategies . reposition ( ) ;
74
+ } ,
75
+ } ,
76
+ ) ;
77
+
65
78
/**
66
79
* Renders out a listbox that can be used to select a time of day.
67
80
* Intended to be used together with `MatTimepickerInput`.
@@ -89,6 +102,7 @@ export class MatTimepicker<D> implements OnDestroy, MatOptionParentComponent {
89
102
private _defaultConfig = inject ( MAT_TIMEPICKER_CONFIG , { optional : true } ) ;
90
103
private _dateAdapter = inject < DateAdapter < D > > ( DateAdapter , { optional : true } ) ! ;
91
104
private _dateFormats = inject ( MAT_DATE_FORMATS , { optional : true } ) ! ;
105
+ private _scrollStrategyFactory = inject ( MAT_TIMEPICKER_SCROLL_STRATEGY ) ;
92
106
protected _animationsDisabled =
93
107
inject ( ANIMATION_MODULE_TYPE , { optional : true } ) === 'NoopAnimations' ;
94
108
@@ -321,7 +335,7 @@ export class MatTimepicker<D> implements OnDestroy, MatOptionParentComponent {
321
335
322
336
this . _overlayRef = this . _overlay . create ( {
323
337
positionStrategy,
324
- scrollStrategy : this . _overlay . scrollStrategies . reposition ( ) ,
338
+ scrollStrategy : this . _scrollStrategyFactory ( ) ,
325
339
direction : this . _dir || 'ltr' ,
326
340
hasBackdrop : false ,
327
341
} ) ;
0 commit comments