Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed render of months when toMonth and numberOfMonth are passed #556

Merged
merged 1 commit into from
Nov 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/DayPicker.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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