Skip to content

Commit 85eafc0

Browse files
committed
fix: allowed-dates not marking disabled months in month-picker (fixes #1008)
1 parent 3f9f1ea commit 85eafc0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/VueDatePicker/components/MonthPicker/month-picker.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
getMaxMonth,
1010
getMinMonth,
1111
isDateBetween,
12+
isMonthAllowed,
1213
resetDate,
1314
setDateMonthOrYear,
1415
} from '@/utils/date-utils';
@@ -136,7 +137,8 @@ export const useMonthPicker = (props: PickerBasePropsType, emit: VueEmit) => {
136137
getMaxMonth(year.value(instance), propDates.value.maxDate),
137138
) ||
138139
getDisabledMonths(propDates.value.disabledDates, year.value(instance)).includes(month.value) ||
139-
defaultedFilters.value.months?.includes(month.value);
140+
defaultedFilters.value.months?.includes(month.value) ||
141+
!isMonthAllowed(propDates.value.allowedDates, year.value(instance), month.value);
140142
const isBetween = isMonthBetween(month.value, instance);
141143
const highlighted = checkHighlightMonth(defaultedHighlight.value, month.value, year.value(instance));
142144
return { active, disabled, isBetween, highlighted };

src/VueDatePicker/utils/date-utils.ts

+14
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,20 @@ export const getDisabledMonths = (
415415
return [];
416416
};
417417

418+
export const isMonthAllowed = (
419+
disabledDates: Map<string, Date | null> | null | ((date: Date) => boolean),
420+
year: number,
421+
month: number,
422+
) => {
423+
if (disabledDates instanceof Map) {
424+
const months = Array.from(disabledDates.values())
425+
.filter((date) => getYear(getDate(date)) === year)
426+
.map((date) => getMonth(date as Date));
427+
return months.length ? months.includes(month) : true;
428+
}
429+
return true;
430+
};
431+
418432
export const checkHighlightMonth = (defaultedHighlight: Highlight | HighlightFn, month: number, year: number) => {
419433
return typeof defaultedHighlight === 'function'
420434
? defaultedHighlight({ month: month, year })

0 commit comments

Comments
 (0)