react-day-picker
react-day-picker copied to clipboard
DayPickerInput: input value does not update when the locale changes
Basically when the "dayPickerProps.locale" or "format" props change the value of the input component does not get recomputed (call formatDate)
I had something similar going on! Perhaps my solution can help you? I was trying to reset the input value to an empty string.
Parent component:
_clearDates = (datePickerFrom, datePickerTo) => {
datePickerFrom.state.value = ''; <- The input value can be changed here, not on datePickerFrom.input.value
datePickerTo.state.value = '';
this.setState({ from: undefined, to: undefined, dateError: false })
};
Datepicker component:
_clearDates = () => this.props.clearDates(this.from, this.to);
// Inside render
<DayPickerInput
ref={el => (this.from = el)} <- REALLY important to set this
...
</>
<DayPickerInput
ref={el => (this.to = el)}
...
</>
<Button icon="delete" onClick={_clearDates}/>
I passed the reference to my DayPickerInput to the parent component, but that's not necessary. However, I'm also confused as to why the input value doesn't get updated along with everything else. My props and state are all being updated correctly, but the input value is not. 🤷♀This should definitely be looked into. I hope this helps a bit.