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
date
field in state, passed as thevalue
prop toDatePicker
- Change the
date
tonull
when desired to 'clear' the value & input
The behaviour I observe:
- If the
date
is valid, it works as expected, and the input is cleared - If the
date
is not valid, theerror
is 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.