From fb8df1f6a17de84a6d963161c6042fad56c24ec5 Mon Sep 17 00:00:00 2001 From: Jasenko Karovic Date: Sat, 4 Jan 2025 21:59:25 +0100 Subject: [PATCH] fix: Reset start time on value clear (fixes #1048) --- src/VueDatePicker/VueDatePicker.vue | 1 + .../components/DatePicker/DatePicker.vue | 2 ++ .../components/DatePicker/date-picker.ts | 12 +++++++++--- src/VueDatePicker/components/DatepickerMenu.vue | 5 +++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/VueDatePicker/VueDatePicker.vue b/src/VueDatePicker/VueDatePicker.vue index 76dc5b75..b43ee4e7 100644 --- a/src/VueDatePicker/VueDatePicker.vue +++ b/src/VueDatePicker/VueDatePicker.vue @@ -343,6 +343,7 @@ const clearValue = (): void => { inputValue.value = ''; clearInternalValues(); + dpMenuRef.value?.onValueCleared(); inputRef.value?.setParsedDate(null); emit('update:model-value', null); emit('update:model-timezone-value', null); diff --git a/src/VueDatePicker/components/DatePicker/DatePicker.vue b/src/VueDatePicker/components/DatePicker/DatePicker.vue index be2a4aa0..0716b71f 100644 --- a/src/VueDatePicker/components/DatePicker/DatePicker.vue +++ b/src/VueDatePicker/components/DatePicker/DatePicker.vue @@ -150,6 +150,7 @@ selectCurrentDate, updateTime, assignMonthAndYear, + setStartTime, } = useDatePicker(props, emit, triggerCalendarTransition, updateFlowStep); const slots = useSlots(); const { setHoverDate, getDayClassData, clearHoverDate } = useCalendarClass(modelValue, props); @@ -303,5 +304,6 @@ changeMonth, changeYear, selectWeekDate, + setStartTime, }); diff --git a/src/VueDatePicker/components/DatePicker/date-picker.ts b/src/VueDatePicker/components/DatePicker/date-picker.ts index 9b84dc95..21d631b2 100644 --- a/src/VueDatePicker/components/DatePicker/date-picker.ts +++ b/src/VueDatePicker/components/DatePicker/date-picker.ts @@ -63,6 +63,7 @@ export const useDatePicker = ( const { validateMonthYearInRange, isDisabled, isDateRangeAllowed, checkMinMaxRange } = useValidation(props); const { updateTimeValues, getSetDateTime, setTime, assignStartTime, validateTime, disabledTimesConfig } = useTimePickerUtils(props, time, modelValue, updateFlow); + // Get month based on the calendar instance const month = computed( () => @@ -104,13 +105,17 @@ export const useDatePicker = ( } }; + const setStartTime = () => { + if (defaultedStartTime.value) { + assignStartTime(defaultedStartTime.value); + } + }; + onMounted(() => { if (!props.shadow) { if (!modelValue.value) { setStartDate(); - if (defaultedStartTime.value) { - assignStartTime(defaultedStartTime.value); - } + setStartTime(); } mapInternalModuleValues(true); if (props.focusStartDate && props.startDate) { @@ -675,5 +680,6 @@ export const useDatePicker = ( selectCurrentDate, updateTime, assignMonthAndYear, + setStartTime, }; }; diff --git a/src/VueDatePicker/components/DatepickerMenu.vue b/src/VueDatePicker/components/DatepickerMenu.vue index b8b6f9c3..f72f410d 100644 --- a/src/VueDatePicker/components/DatepickerMenu.vue +++ b/src/VueDatePicker/components/DatepickerMenu.vue @@ -434,9 +434,14 @@ } }; + const onValueCleared = () => { + dynCmpRef.value?.setStartTime?.(); + }; + defineExpose({ updateMonthYear, switchView, handleFlow, + onValueCleared, });