From 270fdbc63afd1e15231258c61d148ddf98001217 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Thu, 19 Nov 2015 19:07:06 -0500 Subject: [PATCH] Fix bug where endpoint months could not be shown --- src/DayPicker.js | 4 ++-- test/DayPicker.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/DayPicker.js b/src/DayPicker.js index 88bfece435..b2bab22d1a 100644 --- a/src/DayPicker.js +++ b/src/DayPicker.js @@ -93,8 +93,8 @@ export default class DayPicker extends Component { allowMonth(d) { const { fromMonth, toMonth } = this.props; - if ((fromMonth && Helpers.getMonthsDiff(fromMonth, d) <= 0) || - (toMonth && Helpers.getMonthsDiff(toMonth, d) >= 0)) { + if ((fromMonth && Helpers.getMonthsDiff(fromMonth, d) < 0) || + (toMonth && Helpers.getMonthsDiff(toMonth, d) > 0)) { return false; } return true; diff --git a/test/DayPicker.js b/test/DayPicker.js index a98541dfa1..318c6b6404 100644 --- a/test/DayPicker.js +++ b/test/DayPicker.js @@ -434,6 +434,25 @@ describe("DayPicker", () => { expect(dayPickerEl.state.currentMonth.getFullYear()).to.equal(2015); }); + it("can show the first allowed month, `fromMonth`", () => { + const dayPickerEl = TestUtils.renderIntoDocument( + + ); + dayPickerEl.showMonth(new Date(2015, 4)); + + expect(dayPickerEl.state.currentMonth.getMonth()).to.equal(4); + expect(dayPickerEl.state.currentMonth.getFullYear()).to.equal(2015); + }); + + it("can show the last allowed month, `toMonth`", () => { + const dayPickerEl = TestUtils.renderIntoDocument( + + ); + dayPickerEl.showMonth(new Date(2015, 8)); + + expect(dayPickerEl.state.currentMonth.getMonth()).to.equal(8); + expect(dayPickerEl.state.currentMonth.getFullYear()).to.equal(2015); + }); }); it("displays a modified state upon changing initialMonth prop", (done) => {