Skip to content

Commit

Permalink
Rename to shouldDisableMonthNavigation
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroabreu committed Nov 17, 2018
1 parent c209a9a commit 4693794
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
50 changes: 29 additions & 21 deletions src/components/DayPickerRangeController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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),
Expand All @@ -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 = {};
Expand All @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions test/components/DayPickerRangeController_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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((
<DayPickerRangeController
onDatesChange={sinon.stub()}
onFocusChange={sinon.stub()}
/>
));
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', () => {
Expand Down

0 comments on commit 4693794

Please sign in to comment.