Code example with Formik (not reproducible): https://stackblitz.com/edit/next-typescript-ffn4ta?file=components/CustomDateTimePicker.tsx
Well, mui-x DateTimePicker v5 used to provide us onBlur or onChange with event, so that we can communicate with 3rd party library (like doing onChange={e => onChange(e.target.value)} or so).
But this time, we have values like date or string instead of event.
How do I manage to it work with Formik (or something else)?
I am expecting DateTimePicker to work with Formik (also other 3rd part libs)
Thus, we can use like:
<DateTimePicker
value={value}
onChange={newValue => onChange(new ChangeEvent(...))}
onBlur={() => onBlur(new FocusEvent('blur'))}
/>
Sorry if this isn't answering your question, but you're able to add onFocus and onBlur functionality to date picker with the following! Docs here under the textField slot prop.
const [isDateFieldFocused, setDateFieldFocused] = useState(false);
const handleDateFieldFocus = () => {
setDateFieldFocused(true);
};
const handleDateFieldBlur = () => {
setDateFieldFocused(false);
};
<StyledDatePicker
value={value}
onChange={(newValue: any) => onChange(newValue)}
slotProps={{
textField: {
onFocus: handleDateFieldFocus,
onBlur: handleDateFieldBlur,
},
}}
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With