I would like to add a 'clear' button to a DatePicker from @mui/lab (5.0.0-alpha.55).
What I am attempting:
- Store a
datefield in state, passed as thevalueprop toDatePicker - Change the
datetonullwhen desired to 'clear' the value & input
The behaviour I observe:
- If the
dateis valid, it works as expected, and the input is cleared - If the
dateis not valid, theerroris cleared, but the invalid date still stays in the input.
The rudimentary version I have attempted which shows the behaviour above can be seen here.
If you input a partial date, then click clear, you can observe that the input does not get cleared.
I would prefer to avoid a solution that involves changing the key, as that brings other issues, such as not respecting an external source changing the date to null, and needing additional hacks to respect the label transition when clearing the input.