Skip to content

Commit 8845024

Browse files
committed
fix: Calendar not reflecting values on text-picker in specific modes (fixes #893)
1 parent d9b296c commit 8845024

File tree

6 files changed

+42
-19
lines changed

6 files changed

+42
-19
lines changed

src/VueDatePicker/components/DatePicker/date-picker.ts

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { computed, onMounted, ref, nextTick, watch } from 'vue';
1+
import { computed, onMounted, ref, nextTick } from 'vue';
22
import {
33
add,
44
addDays,
@@ -48,8 +48,9 @@ export const useDatePicker = (
4848
const tempRange = ref<Date[]>([]);
4949
const lastScrollTime = ref(new Date());
5050
const clickedDate = ref<ICalendarDay | undefined>();
51+
const reMap = () => mapInternalModuleValues(props.isTextInputDate);
5152

52-
const { modelValue, calendars, time, today } = useModel(props, emit);
53+
const { modelValue, calendars, time, today } = useModel(props, emit, reMap);
5354
const {
5455
defaultedMultiCalendars,
5556
defaultedStartTime,
@@ -103,16 +104,6 @@ export const useDatePicker = (
103104
}
104105
};
105106

106-
watch(
107-
modelValue,
108-
(newVal, oldVal) => {
109-
if (JSON.stringify(newVal) !== JSON.stringify(oldVal)) {
110-
mapInternalModuleValues(props.isTextInputDate);
111-
}
112-
},
113-
{ deep: true },
114-
);
115-
116107
onMounted(() => {
117108
if (!props.shadow) {
118109
if (!modelValue.value) {

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ export const useMonthPicker = (props: PickerBasePropsType, emit: VueEmit) => {
3838
defaultedFilters,
3939
defaultedMultiDates,
4040
} = useDefaults(props);
41-
42-
const { modelValue, year, month: instanceMonth, calendars } = useModel(props, emit);
41+
const reMap = () => {
42+
if (props.isTextInputDate) onYearSelect(getYear(getDate(props.startDate)), 0);
43+
};
44+
const { modelValue, year, month: instanceMonth, calendars } = useModel(props, emit, reMap);
4345
const months = computed(() => getMonths(props.formatLocale, props.locale, props.monthNameFormat));
4446
const hoverDate = ref<Date | null>(null);
4547
const { checkMinMaxRange } = useValidation(props);

src/VueDatePicker/components/TimePicker/time-picker.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import type { TimeModel, VueEmit } from '@/interfaces';
1010
import { localToTz } from '@/utils/timezone';
1111

1212
export const useTimePicker = (props: PickerBasePropsType, emit: VueEmit) => {
13-
const { modelValue, time } = useModel(props, emit);
13+
const reMap = () => {
14+
if (props.isTextInputDate) setTimeFromModel();
15+
};
16+
const { modelValue, time } = useModel(props, emit, reMap);
1417
const { defaultedStartTime, defaultedRange, defaultedTz } = useDefaults(props);
1518
const { updateTimeValues, getSetDateTime, setTime, assignStartTime, disabledTimesConfig, validateTime } =
1619
useTimePickerUtils(props, time, modelValue, updateFlowStep);

src/VueDatePicker/components/YearPicker/year-picker.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import type { PickerBasePropsType } from '@/props';
1717
import type { VueEmit, IDefaultSelect } from '@/interfaces';
1818

1919
export const useYearPicker = (props: PickerBasePropsType, emit: VueEmit) => {
20-
const { modelValue } = useModel(props, emit);
20+
const reMap = () => {
21+
if (props.isTextInputDate) focusYear.value = getYear(getDate(props.startDate));
22+
};
23+
const { modelValue } = useModel(props, emit, reMap);
2124
const hoverDate = ref<Date | null>(null);
2225
const { defaultedHighlight, defaultedMultiDates, defaultedFilters, defaultedRange, propDates } = useDefaults(props);
2326
const focusYear = ref();

src/VueDatePicker/components/shared/month-quarter-picker.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { computed, onMounted, ref } from 'vue';
1+
import { computed, onMounted, ref, watch } from 'vue';
22
import { addYears, differenceInYears, endOfYear, getMonth, getYear, set, startOfYear, subYears } from 'date-fns';
33

44
import { checkHighlightYear, getDate, getMinMaxYear, resetDate, validateMonthYear } from '@/utils/date-utils';
@@ -114,11 +114,23 @@ export const useMonthOrQuarterPicker = ({
114114
}
115115
};
116116

117-
onMounted(() => {
117+
const assign = () => {
118118
checkModelValue();
119119
if (multiCalendars.value.count) {
120120
assignMultiCalendars();
121121
}
122+
};
123+
124+
watch(modelValue, (newVal, oldVal) => {
125+
if (props.isTextInputDate) {
126+
if (JSON.stringify(newVal ?? {}) !== JSON.stringify(oldVal ?? {})) {
127+
assign();
128+
}
129+
}
130+
});
131+
132+
onMounted(() => {
133+
assign();
122134
});
123135

124136
const selectYear = (year: number, instance: number) => {

src/VueDatePicker/composables/model.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { PickerBasePropsType } from '@/props';
88
import { useDefaults } from '@/composables/defaults';
99
import { localToTz } from '@/utils/timezone';
1010

11-
export const useModel = (props: PickerBasePropsType, emit: VueEmit) => {
11+
export const useModel = (props: PickerBasePropsType, emit: VueEmit, reMap?: () => void) => {
1212
const { defaultedRange, defaultedTz } = useDefaults(props);
1313

1414
const today = getDate(localToTz(getDate(), defaultedTz.value.timezone));
@@ -66,6 +66,18 @@ export const useModel = (props: PickerBasePropsType, emit: VueEmit) => {
6666
calendars.value[instance] ? calendars.value[instance].year : 0,
6767
);
6868

69+
watch(
70+
modelValue,
71+
(newVal, oldVal) => {
72+
if (reMap) {
73+
if (JSON.stringify(newVal ?? {}) !== JSON.stringify(oldVal ?? {})) {
74+
reMap();
75+
}
76+
}
77+
},
78+
{ deep: true },
79+
);
80+
6981
return {
7082
calendars,
7183
time,

0 commit comments

Comments
 (0)