Clear the value of internal input if cleared value passed as prop
I'm Submitting a ...
[ ] Bug report
[x] Feature request
[ ] Support request
Expected Results
Without creating a wrapper, it should be possible to clear the value of the Datetime's component input. By having a cleared value, the Datetime component should clear the input's value too.
Actual Results
The Datetime component's value is cleared but leaves the input's value uncleared.
Minimal Reproduction of the Problem
- Open https://codesandbox.io/s/clear-react-datetime-4zur7
- Click on the input
- Select a date via the calendar
- Press the
clearbutton to clear the value passed toDatetime
This a bug since the prop is there already but is not updating the UI on state changes. I was able to use querySelector from the console, target the input and clear it that way. But even adding that to my code still would not clear the input. It's maddening. please fix...
Stuck with the same issue. Any workaround for this issue?
I had this issue too and managed to fix it by setting inputProps.value to an empty string if the prop value is falsey, and then using inputProps in the DateTime component - see below for an example:
const MyComponent = ({
value,
...
}) => {
let inputProps = { readOnly: true };
if (!value) {
inputProps.value = '';
}
return <Datetime inputProps={inputProps} ... />
}
@dominiceden Thanks a lot. Your suggestion worked for me