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

Commit 077aab7

Browse files
committed
fix: Month year select filters available for select on arrows
1 parent eb3fd98 commit 077aab7

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

src/Vue3DatePicker/components/DatepickerMenu.vue

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</template>
4141

4242
<script lang="ts">
43-
import { computed, defineComponent, onMounted, PropType, ref, nextTick } from 'vue';
43+
import { computed, defineComponent, onMounted, PropType, nextTick } from 'vue';
4444
import Calendar from './Calendar.vue';
4545
4646
import { DatepickerMenuProps, IMonth, DynamicClass, FormatOptions, IDateFilter, ITimeRange } from '../interfaces';
@@ -88,20 +88,19 @@
8888
openOnTop: { type: Boolean as PropType<boolean>, default: false },
8989
},
9090
setup(props: DatepickerMenuProps, { emit }) {
91-
const assignedFilter = ref({});
92-
9391
onMounted(() => {
94-
assignedFilter.value = Object.assign(
95-
{ months: [], years: [], times: { hours: [], minutes: [] } },
96-
props.filters,
97-
);
9892
nextTick(() => emit('dpOpen'));
9993
});
10094
10195
const mappedMonths = computed((): IMonth[] =>
10296
getMonthNames(props.locale).map((month: string, i: number) => ({ text: month, value: i })),
10397
);
10498
99+
const assignedFilter = computed(
100+
(): IDateFilter =>
101+
Object.assign({ months: [], years: [], times: { hours: [], minutes: [] } }, props.filters),
102+
);
103+
105104
const dpMenuClass = computed(
106105
(): DynamicClass => ({
107106
[props.menuClassName]: !!props.menuClassName,

src/Vue3DatePicker/components/SelectionGrid.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
v-for="col in row"
88
:key="col.value"
99
@click="onClick(col.value)"
10-
:id="col.value === modelValue ? 'selection-active' : null"
10+
:id="col.value === modelValue && !disabledValues.includes(col.value) ? 'selection-active' : null"
1111
>
1212
<div :class="col.className">
1313
{{ col.text }}

src/Vue3DatePicker/utils/hooks.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { computed, ComputedRef, Ref } from 'vue';
33
import { generateHours, generateMinutes, getCalendarDays } from './util';
44

55
export const useMontYearPick = (props: MonthYearPickerProps, emit: VueEmit): IMonthYearHook => {
6+
const months = props.months.map((month) => month.value);
7+
const years = props.years.map((year) => year.value);
8+
const excludedMonths = months.filter((month) => !props.filters.months.some((mon) => mon === month));
9+
const excludedYears = years.filter((year) => !props.filters.years.some((yr) => yr === year));
10+
611
const onNext = (): void => {
12+
let tempMonth;
713
let month = props.month;
814
let year = props.year;
915
if (props.month === 11) {
@@ -12,10 +18,29 @@ export const useMontYearPick = (props: MonthYearPickerProps, emit: VueEmit): IMo
1218
} else {
1319
month += 1;
1420
}
21+
if (props.filters.months.includes(month)) {
22+
if (month === 0) {
23+
month = Math.min(...excludedMonths);
24+
} else {
25+
month = Math.max(...excludedMonths);
26+
}
27+
tempMonth = month;
28+
}
29+
if (month === tempMonth) {
30+
month = Math.min(...excludedMonths);
31+
year = props.year + 1;
32+
}
33+
if (props.filters.years.includes(year)) {
34+
const foundYear = excludedYears.find((availableYear) => availableYear > year);
35+
if (foundYear) {
36+
year = foundYear;
37+
}
38+
}
1539
updateMonthYear(month, year);
1640
};
1741

1842
const onPrev = (): void => {
43+
let tempMonth;
1944
let month = props.month;
2045
let year = props.year;
2146
if (props.month === 0) {
@@ -24,6 +49,24 @@ export const useMontYearPick = (props: MonthYearPickerProps, emit: VueEmit): IMo
2449
} else {
2550
month -= 1;
2651
}
52+
if (props.filters.months.includes(month)) {
53+
if (month === 11) {
54+
month = Math.max(...excludedMonths);
55+
} else {
56+
month = Math.min(...excludedMonths);
57+
}
58+
tempMonth = month;
59+
}
60+
if (month === tempMonth) {
61+
month = Math.max(...excludedMonths);
62+
year = props.year - 1;
63+
}
64+
if (props.filters.years.includes(year)) {
65+
const foundYear = excludedYears.reverse().find((availableYear) => availableYear < year);
66+
if (foundYear) {
67+
year = foundYear;
68+
}
69+
}
2770
updateMonthYear(month, year);
2871
};
2972

0 commit comments

Comments
 (0)