diff --git a/src/DayPicker.js b/src/DayPicker.js index 6806b7cf59..c0c44dd0a8 100644 --- a/src/DayPicker.js +++ b/src/DayPicker.js @@ -173,6 +173,14 @@ export default class DayPicker extends Component { props.fromMonth, Math.floor(diffInMonths / props.numberOfMonths) * props.numberOfMonths ); + } else if (props.toMonth && props.numberOfMonths > 1) { + const diffInMonths = Helpers.getMonthsDiff(props.toMonth, currentMonth); + if (diffInMonths <= 0) { + currentMonth = DateUtils.addMonths( + props.toMonth, + 1 - this.props.numberOfMonths + ); + } } return { currentMonth }; }; diff --git a/test/daypicker/navigation.js b/test/daypicker/navigation.js index 04372c0b48..980ce75528 100644 --- a/test/daypicker/navigation.js +++ b/test/daypicker/navigation.js @@ -235,6 +235,18 @@ describe('DayPicker’s navigation', () => { expect(instance.state.currentMonth.getMonth()).toBe(5); expect(instance.state.currentMonth.getDate()).toBe(1); }); + it('should set the currentMonth to the first rendered month if toMonth equals current month', () => { + const instance = shallow( + + ).instance(); + expect(instance.state.currentMonth.getFullYear()).toBe(2015); + expect(instance.state.currentMonth.getMonth()).toBe(5); + expect(instance.state.currentMonth.getDate()).toBe(1); + }); describe('with custom classNames', () => { const getDaysInMonth = wrapper =>