Skip to content

Commit b98f2d7

Browse files
committed
Calendar: fixed issue with going back when last day selected
Fixes #2386
1 parent 70b514f commit b98f2d7

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/core/components/calendar/calendar-class.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ class Calendar extends Framework7Class {
585585
}
586586
prevMonth(transition) {
587587
const calendar = this;
588-
const { params, $wrapperEl, inverter, isHorizontal: isH } = calendar;
588+
const { params, $wrapperEl, inverter, isHorizontal: isH, currentYear, currentMonth } = calendar;
589589
if (typeof transition === 'undefined' || typeof transition === 'object') {
590590
transition = ''; // eslint-disable-line
591591
if (!params.animate) transition = 0; // eslint-disable-line
@@ -596,7 +596,9 @@ class Calendar extends Framework7Class {
596596
const prevDateTime = prevDate.getTime();
597597
const transitionEndCallback = !calendar.animating;
598598
if (params.minDate) {
599-
if (prevDateTime < new Date(params.minDate).getTime()) {
599+
let minDate = new Date(params.minDate);
600+
minDate = new Date(minDate.getFullYear(), minDate.getMonth(), 1);
601+
if (prevDateTime < minDate.getTime()) {
600602
calendar.resetMonth();
601603
return;
602604
}
@@ -660,8 +662,12 @@ class Calendar extends Framework7Class {
660662
if (params.maxDate && targetDate > new Date(params.maxDate).getTime()) {
661663
return false;
662664
}
663-
if (params.minDate && targetDate < new Date(params.minDate).getTime()) {
664-
return false;
665+
if (params.minDate) {
666+
let minDate = new Date(params.minDate);
667+
minDate = new Date(minDate.getFullYear(), minDate.getMonth(), 1);
668+
if (targetDate < minDate.getTime()) {
669+
return false;
670+
}
665671
}
666672
const currentDate = new Date(calendar.currentYear, calendar.currentMonth).getTime();
667673
const dir = targetDate > currentDate ? 'next' : 'prev';

0 commit comments

Comments
 (0)