@@ -74,43 +74,13 @@ export const TimePicker = React.forwardRef<ComboboxInputElement, TimePickerProps
7474 return separator ;
7575 } , [ formatter ] ) ;
7676
77- // Enable virtualization for small steps that generate many options
78- // step=1 -> 1440 options, step=5 -> 288 options
79- const shouldVirtualize = step <= 5 ;
80-
81- // Increase overscan for smoother scrolling with many items
82- const overscanCount = step === 1 ? 15 : 10 ;
83-
84- // For virtualized lists, generate options lazily to avoid creating 1440 React elements upfront
85- // For non-virtualized lists, generate all options as before
77+ // Generate all time options - Combobox will automatically virtualize if > 100
8678 const timeOptions = React . useMemo ( ( ) => {
87- if ( ! shouldVirtualize ) {
88- // Non-virtualized: generate all options as before
89- const stepCount = 60 / step ;
90- return [ ...Array ( 24 ) . keys ( ) ] . flatMap ( ( hour ) =>
91- [ ...Array ( stepCount ) . keys ( ) ] . map ( ( minuteStep ) =>
92- formatter . format ( new Date ( 0 , 0 , 0 , hour , minuteStep * step ) ) ,
93- ) ,
94- ) ;
95- }
96-
97- // Virtualized: return empty array and generate on-demand
98- return [ ] ;
99- } , [ step , formatter , shouldVirtualize ] ) ;
100-
101- // Generate time option on demand for virtualized lists
102- const getTimeOption = React . useCallback (
103- ( index : number ) => {
104- const stepCount = 60 / step ;
105- const hour = Math . floor ( index / stepCount ) ;
106- const minuteStep = index % stepCount ;
107- return formatter . format ( new Date ( 0 , 0 , 0 , hour , minuteStep * step ) ) ;
108- } ,
109- [ step , formatter ] ,
110- ) ;
111-
112- // Calculate total count for virtualized lists
113- const totalTimeCount = ( 60 / step ) * 24 ;
79+ const stepCount = 60 / step ;
80+ return [ ...Array ( 24 ) . keys ( ) ] . flatMap ( ( hour ) =>
81+ [ ...Array ( stepCount ) . keys ( ) ] . map ( ( minuteStep ) => formatter . format ( new Date ( 0 , 0 , 0 , hour , minuteStep * step ) ) ) ,
82+ ) ;
83+ } , [ step , formatter ] ) ;
11484
11585 const handleTextValueChange = ( string ?: string ) => {
11686 if ( ! string || isNotAlphabeticalCharacter ( string ) ) {
@@ -167,19 +137,6 @@ export const TimePicker = React.forwardRef<ComboboxInputElement, TimePickerProps
167137 const escapedSeparator = escapeForRegex ( separator ) ;
168138 const pattern = `\\d{2}${ escapedSeparator } \\d{2}` ;
169139
170- // Render function for lazy virtualization
171- const renderTimeOption = React . useCallback (
172- ( index : number ) => {
173- const time = getTimeOption ( index ) ;
174- return (
175- < ComboboxOption key = { time } value = { time } >
176- { time }
177- </ ComboboxOption >
178- ) ;
179- } ,
180- [ getTimeOption ] ,
181- ) ;
182-
183140 return (
184141 < TimePickerCombobox
185142 { ...restProps }
@@ -196,17 +153,12 @@ export const TimePicker = React.forwardRef<ComboboxInputElement, TimePickerProps
196153 textValue = { textValue }
197154 onTextValueChange = { handleTextValueChange }
198155 onBlur = { handleBlur }
199- virtualized = { shouldVirtualize }
200- overscan = { overscanCount }
201- virtualItemCount = { shouldVirtualize ? totalTimeCount : undefined }
202- renderVirtualItem = { shouldVirtualize ? renderTimeOption : undefined }
203156 >
204- { ! shouldVirtualize &&
205- timeOptions . map ( ( time ) => (
206- < ComboboxOption key = { time } value = { time } >
207- { time }
208- </ ComboboxOption >
209- ) ) }
157+ { timeOptions . map ( ( time ) => (
158+ < ComboboxOption key = { time } value = { time } >
159+ { time }
160+ </ ComboboxOption >
161+ ) ) }
210162 </ TimePickerCombobox >
211163 ) ;
212164 } ,
0 commit comments