When the CLEAR button is used, the input value becomes Unknown and the error Invalid Date Format is displayed under the input field.
I would expect the value to be an empty string and no error to be displayed.
Here is an example of the issue:
https://codesandbox.io/s/3vm7219x81
I found the problem in my code - my onChange function was trying to format the value without checking for validity:
handleDateChange = date => {
const searchDate = moment(date).format("YYYY-MM-DD");
this.setState({ searchDate });
};
this works:
handleDateChange = date => {
const searchDate = moment(date).isValid()
? moment(date).format('YYYY-MM-DD')
: ''
this.setState({ searchDate })
}
Most helpful comment
I found the problem in my code - my onChange function was trying to format the value without checking for validity:
this works: