datetimepickerdayjsmui-x

Dayjs with MUI X DateTimePicker: Allow empty time


I have a use-case where I need the time of DateTime to be optional. I don’t see this to be possible in the current feature-set of dayJs. No way to override the validator and it no way of passing two formats as valid formats. Does anyone have an idea here? I’d rather not use two components Date and Time but just DateTime.

Formats: d-MMM-yyyy and d-MMM-yyyy HH:ss


Solution

  • Fixed by putting a timefield in the EndAdornment of the datetimepicker. Cut off the time format and update the time when a date and time were picked. Some code to allow tabs and arrow keys to work between components.