From a17b7f20e0a3a0d79165ce1b5f45f4f6b5b5e0b5 Mon Sep 17 00:00:00 2001 From: Remon Oldenbeuving Date: Thu, 3 Jul 2014 17:34:24 -0700 Subject: [PATCH] Update state.date when props.selected changes This solves an issue where the calendar wouldn't immediately switch to the correct view when a user types in another date in the input. --- react-datepicker.js | 6 ++++++ src/calendar.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/react-datepicker.js b/react-datepicker.js index 69432b696..3c30b7758 100644 --- a/react-datepicker.js +++ b/react-datepicker.js @@ -10,6 +10,12 @@ var Calendar = React.createClass({displayName: 'Calendar', }; }, + componentWillReceiveProps: function(nextProps) { + this.setState({ + date: nextProps.selected.clone() + }); + }, + increaseMonth: function() { this.setState({ date: this.state.date.addMonth() diff --git a/src/calendar.js b/src/calendar.js index b957c8639..27d0292a3 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -9,6 +9,12 @@ var Calendar = React.createClass({ }; }, + componentWillReceiveProps: function(nextProps) { + this.setState({ + date: nextProps.selected.clone() + }); + }, + increaseMonth: function() { this.setState({ date: this.state.date.addMonth()