Skip to content

Commit f6f040e

Browse files
figfofujoshblack
authored andcommitted
fix(DatePicker): explicitly update minDate and maxDate (carbon-design-system#4912)
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 85dc01d commit f6f040e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

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

+16-4
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,22 @@ export default class DatePicker extends Component {
383383
}
384384
}
385385

386-
componentDidUpdate({ dateFormat: prevDateFormat }) {
387-
const { dateFormat } = this.props;
388-
if (this.cal && prevDateFormat !== dateFormat) {
389-
this.cal.set({ dateFormat });
386+
componentDidUpdate({
387+
dateFormat: prevDateFormat,
388+
minDate: prevMinDate,
389+
maxDate: prevMaxDate,
390+
}) {
391+
const { dateFormat, minDate, maxDate } = this.props;
392+
if (this.cal) {
393+
if (prevDateFormat !== dateFormat) {
394+
this.cal.set({ dateFormat });
395+
}
396+
if (prevMinDate !== minDate) {
397+
this.cal.set('minDate', minDate);
398+
}
399+
if (prevMaxDate !== maxDate) {
400+
this.cal.set('maxDate', maxDate);
401+
}
390402
}
391403
}
392404

0 commit comments

Comments
 (0)