Skip to content

Commit

Permalink
Refactor showMonthsForOutsideDay → handleOutsideDayPress (for #112)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpbl committed Dec 3, 2015
1 parent 8736051 commit 0684532
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/DayPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,6 @@ export default class DayPicker extends Component {
});
}

// Show the month(s) belonging to an outside day, counting the
// number of months actually shown in the calendar.
showMonthsForOutsideDay(day) {
const { currentMonth } = this.state;
const { numberOfMonths } = this.props;
const diffInMonths = Helpers.getMonthsDiff(currentMonth, day);
if (diffInMonths > 0 && diffInMonths >= numberOfMonths) {
this.showNextMonth();
}
else if (diffInMonths < 0) {
this.showPreviousMonth();
}
}

focusPreviousDay(dayNode) {
const body = dayNode.parentNode.parentNode.parentNode.parentNode;
let dayNodes = body.querySelectorAll(".DayPicker-Day:not(.DayPicker-Day--outside)");
Expand Down Expand Up @@ -283,15 +269,15 @@ export default class DayPicker extends Component {
handleDayTouchTap(e, day, modifiers) {
e.persist();
if (modifiers.indexOf("outside") > -1) {
this.showMonthsForOutsideDay(day);
this.handleOutsideDayPress(day);
}
this.props.onDayTouchTap(e, day, modifiers);
}

handleDayClick(e, day, modifiers) {
e.persist();
if (modifiers.indexOf("outside") > -1) {
this.showMonthsForOutsideDay(day);
this.handleOutsideDayPress(day);
}

this.props.onDayClick(e, day, modifiers);
Expand All @@ -307,6 +293,19 @@ export default class DayPicker extends Component {
this.props.onDayMouseLeave(e, day, modifiers);
}

handleOutsideDayPress(day) {
const { currentMonth } = this.state;
const { numberOfMonths } = this.props;
const diffInMonths = Helpers.getMonthsDiff(currentMonth, day);
if (diffInMonths > 0 && diffInMonths >= numberOfMonths) {
this.showNextMonth();
}
else if (diffInMonths < 0) {
this.showPreviousMonth();
}
}


renderNavBar() {
const baseClass = "DayPicker-NavButton DayPicker-NavButton";
return (
Expand Down

0 comments on commit 0684532

Please sign in to comment.