From 1c763f87b58efb307b72e7dc038a5fc7ba45f8c2 Mon Sep 17 00:00:00 2001 From: Akira Sudoh Date: Tue, 7 Jan 2020 07:32:58 +0900 Subject: [PATCH] fix(date-picker): support changing date format (#4856) This change allows change in `dateFormat` prop after initialization reflected correctly to the underlying Flatpickr. --- packages/react/src/components/DatePicker/DatePicker.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/react/src/components/DatePicker/DatePicker.js b/packages/react/src/components/DatePicker/DatePicker.js index e288203f821f..e6143ab2bb10 100644 --- a/packages/react/src/components/DatePicker/DatePicker.js +++ b/packages/react/src/components/DatePicker/DatePicker.js @@ -383,6 +383,13 @@ export default class DatePicker extends Component { } } + componentDidUpdate({ dateFormat: prevDateFormat }) { + const { dateFormat } = this.props; + if (this.cal && prevDateFormat !== dateFormat) { + this.cal.set({ dateFormat }); + } + } + componentWillUnmount() { if (this.cal) { this.cal.destroy();