@@ -17,6 +17,7 @@ import {
1717 effect ,
1818 ElementRef ,
1919 inject ,
20+ InjectionToken ,
2021 Injector ,
2122 input ,
2223 InputSignal ,
@@ -41,7 +42,7 @@ import {
4142 MatOptionParentComponent ,
4243} from '@angular/material/core' ;
4344import { Directionality } from '@angular/cdk/bidi' ;
44- import { Overlay , OverlayRef } from '@angular/cdk/overlay' ;
45+ import { Overlay , OverlayRef , ScrollStrategy } from '@angular/cdk/overlay' ;
4546import { TemplatePortal } from '@angular/cdk/portal' ;
4647import { _getEventTarget } from '@angular/cdk/platform' ;
4748import { ENTER , ESCAPE , hasModifierKey , TAB } from '@angular/cdk/keycodes' ;
@@ -62,6 +63,18 @@ export interface MatTimepickerSelected<D> {
6263 source : MatTimepicker < D > ;
6364}
6465
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+
6578/**
6679 * Renders out a listbox that can be used to select a time of day.
6780 * Intended to be used together with `MatTimepickerInput`.
@@ -89,6 +102,7 @@ export class MatTimepicker<D> implements OnDestroy, MatOptionParentComponent {
89102 private _defaultConfig = inject ( MAT_TIMEPICKER_CONFIG , { optional : true } ) ;
90103 private _dateAdapter = inject < DateAdapter < D > > ( DateAdapter , { optional : true } ) ! ;
91104 private _dateFormats = inject ( MAT_DATE_FORMATS , { optional : true } ) ! ;
105+ private _scrollStrategyFactory = inject ( MAT_TIMEPICKER_SCROLL_STRATEGY ) ;
92106 protected _animationsDisabled =
93107 inject ( ANIMATION_MODULE_TYPE , { optional : true } ) === 'NoopAnimations' ;
94108
@@ -321,7 +335,7 @@ export class MatTimepicker<D> implements OnDestroy, MatOptionParentComponent {
321335
322336 this . _overlayRef = this . _overlay . create ( {
323337 positionStrategy,
324- scrollStrategy : this . _overlay . scrollStrategies . reposition ( ) ,
338+ scrollStrategy : this . _scrollStrategyFactory ( ) ,
325339 direction : this . _dir || 'ltr' ,
326340 hasBackdrop : false ,
327341 } ) ;
0 commit comments