File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed
packages/ui-components/src/lib/inputs/InputDate Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon';
77import { useFormContext } from '../../hooks' ;
88import { InputText } from '../InputText/InputText' ;
99import { InputProps } from '../InputBase' ;
10+ import { useEffect } from 'react' ;
1011
1112export type InputDateProps = Omit < InputProps , 'onChange' > & {
1213 value ?: Date | string ;
@@ -33,8 +34,13 @@ export const InputDate: FC<InputDateProps> = ({
3334 const formContext = useFormContext ( ) ;
3435 if ( ! formikProps && formContext ) formikProps = formContext ;
3536 const fieldValue = formikProps ? _get ( formikProps ?. values , props . name , '' ) : value ;
37+ const fieldDateTime = valueFormat ? DateTime . fromFormat ( fieldValue , valueFormat ) : DateTime . fromISO ( fieldValue ) ;
3638 const [ inputValue , setInputValue ] = React . useState < DateTime | null > ( fieldValue ) ;
3739
40+ useEffect ( ( ) => {
41+ if ( fieldDateTime . isValid ) setInputValue ( fieldDateTime ) ;
42+ } , [ fieldValue ] ) ;
43+
3844 return (
3945 < LocalizationProvider dateAdapter = { AdapterLuxon } >
4046 < DatePicker
You can’t perform that action at this time.
0 commit comments