react-datetime icon indicating copy to clipboard operation
react-datetime copied to clipboard

Clear the value of internal input if cleared value passed as prop

Open iamdiogo opened this issue 4 years ago • 4 comments

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

  1. Open https://codesandbox.io/s/clear-react-datetime-4zur7
  2. Click on the input
  3. Select a date via the calendar
  4. Press the clear button to clear the value passed to Datetime

iamdiogo avatar Oct 24 '20 12:10 iamdiogo

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...

naeem-gitonga avatar Jan 13 '21 22:01 naeem-gitonga

Stuck with the same issue. Any workaround for this issue?

Priyanga-Mohan avatar Feb 16 '21 09:02 Priyanga-Mohan

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 avatar Jun 24 '21 13:06 dominiceden

@dominiceden Thanks a lot. Your suggestion worked for me

binums avatar Aug 13 '21 10:08 binums