Skip to content

Commit d14d293

Browse files
author
Bui Duc Binh
committed
fix(DatePicker): explicitly update minDate and maxDate
Since flatpickr does not automatically update minDate and maxDate, we need to explicitly do it when the user makes any change in the props by using set(option, value) method from flatpickr
1 parent 0d6f869 commit d14d293

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

packages/react/src/components/DatePicker/DatePicker.js

+11
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,17 @@ export default class DatePicker extends Component {
307307
};
308308

309309
UNSAFE_componentWillUpdate(nextProps) {
310+
//Explicitly update minDate and maxDate
311+
const extraProps = ['minDate', 'maxDate'];
312+
extraProps.forEach(prop => {
313+
if (nextProps[prop] !== this.props[prop]) {
314+
if (this.cal) {
315+
this.cal.set(prop, nextProps[prop]);
316+
} else if (this.inputField) {
317+
this.inputField[prop] = nextProps[prop];
318+
}
319+
}
320+
});
310321
if (nextProps.value !== this.props.value) {
311322
if (this.cal) {
312323
this.cal.setDate(nextProps.value);

0 commit comments

Comments
 (0)