@@ -90,6 +90,7 @@ export interface DateFieldState extends FormValidationState {
9090 /** Sets the value of the given segment. */
9191 setSegment ( type : 'era' , value : string ) : void ,
9292 setSegment ( type : SegmentType , value : number ) : void ,
93+ incrementToMinMax ( type : SegmentType , value : number ) : void ,
9394 /** Updates the remaining unfilled segments with the placeholder value. */
9495 confirmPlaceholder ( ) : void ,
9596 /** Clears the value of the given segment, reverting it to the placeholder. */
@@ -184,7 +185,6 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
184185 props . onChange
185186 ) ;
186187
187-
188188 const previousValue = useRef ( value )
189189
190190 let calendarValue = useMemo ( ( ) => convertValue ( value , calendar ) ?? null , [ value , calendar ] ) ;
@@ -229,16 +229,16 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
229229
230230 // Reset placeholder when calendar changes
231231 let lastCalendar = useRef ( calendar ) ;
232- useEffect ( ( ) => {
233- if ( ! isEqualCalendar ( calendar , lastCalendar . current ) ) {
234- lastCalendar . current = calendar ;
235- setPlaceholderDate ( placeholder =>
236- Object . keys ( validSegments ) . length > 0
237- ? toCalendar ( placeholder , calendar )
238- : createPlaceholderDate ( props . placeholderValue , granularity , calendar , defaultTimeZone )
239- ) ;
240- }
241- } , [ calendar , granularity , validSegments , defaultTimeZone , props . placeholderValue ] ) ;
232+ // useEffect(() => {
233+ // if (!isEqualCalendar(calendar, lastCalendar.current)) {
234+ // lastCalendar.current = calendar;
235+ // setPlaceholderDate(placeholder =>
236+ // Object.keys(validSegments).length > 0
237+ // ? toCalendar(placeholder, calendar)
238+ // : createPlaceholderDate(props.placeholderValue, granularity, calendar, defaultTimeZone)
239+ // );
240+ // }
241+ // }, [calendar, granularity, validSegments, defaultTimeZone, props.placeholderValue]);
242242
243243 // If there is a value prop, and some segments were previously placeholders, mark them all as valid.
244244 if ( value !== previousValue . current && value && Object . keys ( validSegments ) . length <= Object . keys ( allSegments ) . length ) {
@@ -290,14 +290,16 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
290290
291291 // The display calendar should not have any effect on the emitted value.
292292 // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
293- newValue = toCalendar ( newValue , v ?. calendar || new GregorianCalendar ( ) ) ;
294- setDate ( newValue ) ;
295- previousValue . current = newValue
296- setPlaceholderDate ( newValue )
293+ const day = Math . max ( 1 , Math . min ( newValue . calendar . getDaysInMonth ( newValue ) , newValue . day ) ) ;
294+ const constrainedValue = setSegment ( newValue , "day" , day , resolvedOptions )
295+
296+ const value = toCalendar ( constrainedValue , v ?. calendar || new GregorianCalendar ( ) ) ;
297+ setDate ( value ) ;
298+ previousValue . current = value
299+ setPlaceholderDate ( value )
297300 }
298301} ;
299302
300-
301303 let updatePlaceholder = ( newValue : DateValue ) => {
302304 if ( props . isDisabled || props . isReadOnly ) {
303305 return ;
@@ -354,6 +356,9 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
354356 }
355357 } ;
356358
359+
360+
361+
357362 let builtinValidation = useMemo ( ( ) => getValidationResult (
358363 value ,
359364 minValue ,
@@ -405,20 +410,32 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
405410 markValid ( part ) ;
406411 updatePlaceholder ( setSegment ( displayValue , part , v , resolvedOptions ) ) ;
407412 } ,
413+ incrementToMinMax ( part , v : string | number ) {
414+ isValueConfirmed . current = false
415+ setIsValueChanged ( true )
416+ markValid ( part )
417+ let validKeys = Object . keys ( validSegments ) ;
418+ let allKeys = Object . keys ( allSegments ) ;
419+ const value = setSegment ( displayValue , part , v , resolvedOptions )
420+ currentValue . current = value
421+ if ( validKeys . length >= allKeys . length || ( validKeys . length === allKeys . length - 1 && allSegments . dayPeriod && ! validSegments . dayPeriod ) ) {
422+ setValue ( value ) ;
423+ } else {
424+ updatePlaceholder ( value )
425+ }
426+ } ,
408427 confirmPlaceholder ( ) {
409428 if ( props . isDisabled || props . isReadOnly ) {
410429 return ;
411430 }
412431
413- // Confirm the placeholder if only the day period is not filled in.
414432 let validKeys = Object . keys ( validSegments ) ;
415433 let allKeys = Object . keys ( allSegments ) ;
416434 if ( validKeys . length >= allKeys . length ||
417435 ( validKeys . length === allKeys . length - 1 && allSegments . dayPeriod && ! validSegments . dayPeriod && clearedSegment . current !== 'dayPeriod' ) ) {
418436 validSegments = { ...allSegments } ;
419437 setValidSegments ( validSegments ) ;
420- const value = Math . max ( 1 , Math . min ( currentValue . current . calendar . getDaysInMonth ( currentValue . current ) , currentValue . current . day ) ) ;
421- const v = setValue ( setSegment ( currentValue . current , "day" , value , resolvedOptions ) )
438+ // setValue(currentValue.current.copy())
422439 } else {
423440 setDate ( null )
424441 previousValue . current = null
0 commit comments