Skip to content

Commit

Permalink
Fixed render of months when toMonth equals current month
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrognomik committed Nov 23, 2017
1 parent b28dd81 commit 355f861
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/DayPicker.js
Expand Up @@ -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 };
};
Expand Down
12 changes: 12 additions & 0 deletions test/daypicker/navigation.js
Expand Up @@ -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(
<DayPicker
initialMonth={new Date(2015, 7)}
toMonth={new Date(2015, 7)}
numberOfMonths={3}
/>
).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 =>
Expand Down

0 comments on commit 355f861

Please sign in to comment.