Skip to content

Commit

Permalink
fix(DatePicker): explicitly update minDate and maxDate (#4912)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
figfofu authored and joshblack committed Jan 13, 2020
1 parent 85dc01d commit f6f040e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/react/src/components/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,22 @@ export default class DatePicker extends Component {
}
}

componentDidUpdate({ dateFormat: prevDateFormat }) {
const { dateFormat } = this.props;
if (this.cal && prevDateFormat !== dateFormat) {
this.cal.set({ dateFormat });
componentDidUpdate({
dateFormat: prevDateFormat,
minDate: prevMinDate,
maxDate: prevMaxDate,
}) {
const { dateFormat, minDate, maxDate } = this.props;
if (this.cal) {
if (prevDateFormat !== dateFormat) {
this.cal.set({ dateFormat });
}
if (prevMinDate !== minDate) {
this.cal.set('minDate', minDate);
}
if (prevMaxDate !== maxDate) {
this.cal.set('maxDate', maxDate);
}
}
}

Expand Down

0 comments on commit f6f040e

Please sign in to comment.