From 46937947466ec309c230951520bc5dfa091ea759 Mon Sep 17 00:00:00 2001 From: Pedro Abreu Date: Wed, 15 Aug 2018 21:14:34 +0100 Subject: [PATCH] Rename to shouldDisableMonthNavigation --- src/components/DayPickerRangeController.jsx | 50 +++++++++++-------- .../DayPickerRangeController_spec.jsx | 8 +-- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/components/DayPickerRangeController.jsx b/src/components/DayPickerRangeController.jsx index 9530567460..e12c3f9b7c 100644 --- a/src/components/DayPickerRangeController.jsx +++ b/src/components/DayPickerRangeController.jsx @@ -660,7 +660,13 @@ export default class DayPickerRangeController extends React.PureComponent { } onPrevMonthClick() { - const { onPrevMonthClick, numberOfMonths, enableOutsideDays } = this.props; + const { + enableOutsideDays, + maxDate, + minDate, + numberOfMonths, + onPrevMonthClick, + } = this.props; const { currentMonth, visibleDays } = this.state; const newVisibleDays = {}; @@ -674,7 +680,8 @@ export default class DayPickerRangeController extends React.PureComponent { const newCurrentMonth = currentMonth.clone().subtract(1, 'month'); this.setState({ currentMonth: newCurrentMonth, - ...this.getNavigationStatus(newCurrentMonth), + disablePrev: this.shouldDisableMonthNavigation(minDate, newCurrentMonth), + disableNext: this.shouldDisableMonthNavigation(maxDate, newCurrentMonth), visibleDays: { ...newVisibleDays, ...this.getModifiers(prevMonthVisibleDays), @@ -685,7 +692,13 @@ export default class DayPickerRangeController extends React.PureComponent { } onNextMonthClick() { - const { onNextMonthClick, numberOfMonths, enableOutsideDays } = this.props; + const { + enableOutsideDays, + maxDate, + minDate, + numberOfMonths, + onNextMonthClick, + } = this.props; const { currentMonth, visibleDays } = this.state; const newVisibleDays = {}; @@ -698,7 +711,8 @@ export default class DayPickerRangeController extends React.PureComponent { const newCurrentMonth = currentMonth.clone().add(1, 'month'); this.setState({ currentMonth: newCurrentMonth, - ...this.getNavigationStatus(newCurrentMonth), + disablePrev: this.shouldDisableMonthNavigation(minDate, newCurrentMonth), + disableNext: this.shouldDisableMonthNavigation(maxDate, newCurrentMonth), visibleDays: { ...newVisibleDays, ...this.getModifiers(nextMonthVisibleDays), @@ -756,23 +770,6 @@ export default class DayPickerRangeController extends React.PureComponent { }); } - getNavigationStatus(visibleMonth) { - const { - minDate, - maxDate, - numberOfMonths, - enableOutsideDays, - } = this.props; - - const isMinDateVisible = isDayVisible(minDate, visibleMonth, numberOfMonths, enableOutsideDays); - const isMaxDateVisible = isDayVisible(maxDate, visibleMonth, numberOfMonths, enableOutsideDays); - - return { - disablePrev: isMinDateVisible, - disableNext: isMaxDateVisible, - }; - } - getFirstFocusableDay(newMonth) { const { startDate, @@ -848,6 +845,17 @@ export default class DayPickerRangeController extends React.PureComponent { return { currentMonth, visibleDays }; } + shouldDisableMonthNavigation(date, visibleMonth) { + if (!date) return false; + + const { + numberOfMonths, + enableOutsideDays, + } = this.props; + + return isDayVisible(date, visibleMonth, numberOfMonths, enableOutsideDays); + } + addModifier(updatedDays, day, modifier) { const { numberOfMonths: numberOfVisibleMonths, enableOutsideDays, orientation } = this.props; const { currentMonth: firstVisibleMonth, visibleDays } = this.state; diff --git a/test/components/DayPickerRangeController_spec.jsx b/test/components/DayPickerRangeController_spec.jsx index c212e96071..b57f1c9354 100644 --- a/test/components/DayPickerRangeController_spec.jsx +++ b/test/components/DayPickerRangeController_spec.jsx @@ -2050,17 +2050,17 @@ describe('DayPickerRangeController', () => { expect(onPrevMonthClickStub.firstCall.args[0].month()).to.equal(newMonth.month()); }); - it('calls this.getNavigationStatus', () => { - const getNavigationStatusSpy = sinon.spy(DayPickerRangeController.prototype, 'getNavigationStatus'); + it('calls this.shouldDisableMonthNavigation twice', () => { + const shouldDisableMonthNavigationSpy = sinon.spy(DayPickerRangeController.prototype, 'shouldDisableMonthNavigation'); const wrapper = shallow(( )); - getNavigationStatusSpy.resetHistory(); + shouldDisableMonthNavigationSpy.resetHistory(); wrapper.instance().onPrevMonthClick(); - expect(getNavigationStatusSpy.callCount).to.equal(1); + expect(shouldDisableMonthNavigationSpy.callCount).to.equal(2); }); it('sets disablePrev and disablePrev as false on onPrevMonthClick call withouth maxDate and minDate set', () => {