@@ -263,7 +263,6 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
263263 }
264264 // If all segments are valid, use the date from state, otherwise use the placeholder date.
265265 let displayValue = isValueConfirmed && value ? value : placeholderDate ;
266- const currentValue = useRef ( displayValue ) ;
267266 let setValue = ( newValue : DateValue ) => {
268267 if ( props . isDisabled || props . isReadOnly ) {
269268 return ;
@@ -307,7 +306,7 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
307306 if ( props . isDisabled || props . isReadOnly ) {
308307 return ;
309308 }
310- currentValue . current = newValue ;
309+ displayValue = newValue ;
311310 setPlaceholderDate ( newValue ) ;
312311 } ;
313312
@@ -337,25 +336,22 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
337336 let adjustSegment = ( type : Intl . DateTimeFormatPartTypes , amount : number ) => {
338337 setShouldValidate ( true ) ;
339338 setIsValueConfirmed ( false ) ;
340-
339+
340+ let v = displayValue ;
341341 if ( ! validSegments [ type ] ) {
342342 markValid ( type ) ;
343- let validKeys = Object . keys ( validSegments ) ;
344- let allKeys = Object . keys ( allSegments ) ;
345- if ( validKeys . length >= allKeys . length || ( validKeys . length === allKeys . length - 1 && allSegments . dayPeriod && ! validSegments . dayPeriod ) ) {
346- currentValue . current = displayValue ;
347- setValue ( constrainDate ( displayValue ) ) ;
348- } else { updatePlaceholder ( displayValue ) ; }
349343 } else {
350- let validKeys = Object . keys ( validSegments ) ;
351- let allKeys = Object . keys ( allSegments ) ;
352- const v = addSegment ( displayValue , type , amount , resolvedOptions ) ;
353- if ( validKeys . length >= allKeys . length || ( validKeys . length === allKeys . length - 1 && allSegments . dayPeriod && ! validSegments . dayPeriod ) ) {
354- currentValue . current = v ;
355- setValue ( constrainDate ( v ) ) ;
356- } else {
357- updatePlaceholder ( v ) ;
358- }
344+ v = addSegment ( displayValue , type , amount , resolvedOptions ) ;
345+ }
346+
347+ let validKeys = Object . keys ( validSegments ) ;
348+ let allKeys = Object . keys ( allSegments ) ;
349+ if ( validKeys . length >= allKeys . length || ( validKeys . length === allKeys . length - 1 && allSegments . dayPeriod && ! validSegments . dayPeriod ) ) {
350+ const constrained = constrainDate ( v ) ;
351+ displayValue = constrained ;
352+ setValue ( constrained ) ;
353+ } else {
354+ updatePlaceholder ( v ) ;
359355 }
360356 } ;
361357
@@ -420,7 +416,6 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
420416 let validKeys = Object . keys ( validSegments ) ;
421417 let allKeys = Object . keys ( allSegments ) ;
422418 const value = setSegment ( displayValue , part , v , resolvedOptions ) ;
423- currentValue . current = value ;
424419 if ( validKeys . length >= allKeys . length || ( validKeys . length === allKeys . length - 1 && allSegments . dayPeriod && ! validSegments . dayPeriod ) ) {
425420 setValue ( constrainDate ( value ) ) ;
426421 } else {
@@ -438,7 +433,7 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
438433 ( validKeys . length === allKeys . length - 1 && allSegments . dayPeriod && ! validSegments . dayPeriod && clearedSegment . current !== 'dayPeriod' ) ) {
439434 validSegments = { ...allSegments } ;
440435 setValidSegments ( validSegments ) ;
441- setValue ( constrainDate ( currentValue . current ) ) ;
436+ setValue ( constrainDate ( displayValue ) ) ;
442437 } else {
443438 setDate ( null ) ;
444439 setPreviousValue ( null ) ;
0 commit comments