Skip to content
This repository has been archived by the owner on Apr 17, 2022. It is now read-only.

Commit

Permalink
fix: preventMinMaxNavigation disabling wrong arrows (fixes #99)
Browse files Browse the repository at this point in the history
- Minor tweaking
  • Loading branch information
Jasenkoo committed Feb 17, 2022
1 parent 719484c commit c190783
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Vue3DatePicker/components/composition/month-year.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addMonths, addYears, getMonth, getYear, set, subMonths, subYears } from 'date-fns';
import { UseMonthYearPick, VueEmit } from '../../interfaces';
import { isDateAfter, isDateBefore } from '../../utils/date-utils';
import { isDateAfter, isDateBefore, isDateEqual } from '../../utils/date-utils';

export const useMontYearPick = (
props: UseMonthYearPick,
Expand Down Expand Up @@ -28,12 +28,19 @@ export const useMontYearPick = (
return [new Date(props[propValue]), set(new Date(), { month, year })];
};

const validateMonthYear = (month: number, year: number, isNext: boolean): void => {
const validateMonthYear = (month: number, year: number): void => {
if (props.preventMinMaxNavigation && (props.minDate || props.maxDate)) {
if (props.maxDate && isNext && isDateAfter(...getDateForCompare('maxDate', month, year))) {
if (
props.maxDate &&
(isDateAfter(...getDateForCompare('maxDate', month, year)) ||
isDateEqual(...getDateForCompare('maxDate', month, year)))
) {
updateMonthYear(month, year);
}
if (props.minDate && !isNext && isDateBefore(...getDateForCompare('minDate', month, year))) {
if (
(props.minDate && isDateBefore(...getDateForCompare('minDate', month, year))) ||
isDateEqual(...getDateForCompare('minDate', month, year))
) {
updateMonthYear(month, year);
}
} else {
Expand All @@ -58,7 +65,7 @@ export const useMontYearPick = (
date = recursiveYearAdjust(date, isNext);
year = getYear(date);
}
validateMonthYear(month, year, isNext);
validateMonthYear(month, year);
};

const updateMonthYear = (month: number, year: number): void => {
Expand Down

0 comments on commit c190783

Please sign in to comment.