@@ -16,6 +16,7 @@ import {
16
16
effect ,
17
17
ElementRef ,
18
18
inject ,
19
+ InjectionToken ,
19
20
Injector ,
20
21
input ,
21
22
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`.
@@ -101,6 +114,7 @@ export class MatTimepicker<D> implements OnDestroy, MatOptionParentComponent {
101
114
private _defaultConfig = inject ( MAT_TIMEPICKER_CONFIG , { optional : true } ) ;
102
115
private _dateAdapter = inject < DateAdapter < D > > ( DateAdapter , { optional : true } ) ! ;
103
116
private _dateFormats = inject ( MAT_DATE_FORMATS , { optional : true } ) ! ;
117
+ private _scrollStrategyFactory = inject ( MAT_TIMEPICKER_SCROLL_STRATEGY ) ;
104
118
105
119
private _isOpen = signal ( false ) ;
106
120
private _activeDescendant = signal < string | null > ( null ) ;
@@ -314,7 +328,7 @@ export class MatTimepicker<D> implements OnDestroy, MatOptionParentComponent {
314
328
315
329
this . _overlayRef = this . _overlay . create ( {
316
330
positionStrategy,
317
- scrollStrategy : this . _overlay . scrollStrategies . reposition ( ) ,
331
+ scrollStrategy : this . _scrollStrategyFactory ( ) ,
318
332
direction : this . _dir || 'ltr' ,
319
333
hasBackdrop : false ,
320
334
} ) ;
0 commit comments