@@ -200,8 +200,13 @@ export const useFieldCharacterEditing = <TValue extends PickerValidValue>({
200
200
} ;
201
201
202
202
const applyNumericEditing : CharacterEditingApplier = ( params ) => {
203
- const getNewSectionValue = (
204
- queryValue : string ,
203
+ const getNewSectionValue = ( {
204
+ queryValue,
205
+ skipIfBelowMinimum,
206
+ section,
207
+ } : {
208
+ queryValue : string ;
209
+ skipIfBelowMinimum : boolean ;
205
210
section : Pick <
206
211
FieldSection ,
207
212
| 'format'
@@ -210,8 +215,8 @@ export const useFieldCharacterEditing = <TValue extends PickerValidValue>({
210
215
| 'hasLeadingZerosInFormat'
211
216
| 'hasLeadingZerosInInput'
212
217
| 'maxLength'
213
- > ,
214
- ) : ReturnType < QueryApplier < TValue > > => {
218
+ > ;
219
+ } ) : ReturnType < QueryApplier < TValue > > => {
215
220
const cleanQueryValue = removeLocalizedDigits ( queryValue , localizedDigits ) ;
216
221
const queryValueNumber = Number ( cleanQueryValue ) ;
217
222
const sectionBoundaries = sectionsValueBoundaries [ section . type ] ( {
@@ -227,7 +232,7 @@ export const useFieldCharacterEditing = <TValue extends PickerValidValue>({
227
232
// If the user types `0` on a month section,
228
233
// It is below the minimum, but we want to store the `0` in the query,
229
234
// So that when he pressed `1`, it will store `01` and move to the next section.
230
- if ( queryValueNumber < sectionBoundaries . minimum ) {
235
+ if ( skipIfBelowMinimum && queryValueNumber < sectionBoundaries . minimum ) {
231
236
return { saveQuery : true } ;
232
237
}
233
238
@@ -254,7 +259,11 @@ export const useFieldCharacterEditing = <TValue extends PickerValidValue>({
254
259
activeSection . contentType === 'digit' ||
255
260
activeSection . contentType === 'digit-with-letter'
256
261
) {
257
- return getNewSectionValue ( queryValue , activeSection ) ;
262
+ return getNewSectionValue ( {
263
+ queryValue,
264
+ skipIfBelowMinimum : false ,
265
+ section : activeSection ,
266
+ } ) ;
258
267
}
259
268
260
269
// When editing a letter-format month and the user presses a digit,
@@ -267,13 +276,17 @@ export const useFieldCharacterEditing = <TValue extends PickerValidValue>({
267
276
'MM' ,
268
277
) ;
269
278
270
- const response = getNewSectionValue ( queryValue , {
271
- type : activeSection . type ,
272
- format : 'MM' ,
273
- hasLeadingZerosInFormat,
274
- hasLeadingZerosInInput : true ,
275
- contentType : 'digit' ,
276
- maxLength : 2 ,
279
+ const response = getNewSectionValue ( {
280
+ queryValue,
281
+ skipIfBelowMinimum : true ,
282
+ section : {
283
+ type : activeSection . type ,
284
+ format : 'MM' ,
285
+ hasLeadingZerosInFormat,
286
+ hasLeadingZerosInInput : true ,
287
+ contentType : 'digit' ,
288
+ maxLength : 2 ,
289
+ } ,
277
290
} ) ;
278
291
279
292
if ( isQueryResponseWithoutValue ( response ) ) {
@@ -296,7 +309,11 @@ export const useFieldCharacterEditing = <TValue extends PickerValidValue>({
296
309
// When editing a letter-format weekDay and the user presses a digit,
297
310
// We can support the numeric editing by returning the nth day in the week day array.
298
311
if ( activeSection . type === 'weekDay' ) {
299
- const response = getNewSectionValue ( queryValue , activeSection ) ;
312
+ const response = getNewSectionValue ( {
313
+ queryValue,
314
+ skipIfBelowMinimum : true ,
315
+ section : activeSection ,
316
+ } ) ;
300
317
if ( isQueryResponseWithoutValue ( response ) ) {
301
318
return response ;
302
319
}
0 commit comments