From a79a5ee37f52714bc79bdf59b1cc766efca61229 Mon Sep 17 00:00:00 2001 From: "alexandr.epihin" Date: Fri, 13 May 2022 15:44:50 +0300 Subject: [PATCH] fix: update timepicker after manual entry --- src/datepicker/Timepicker.vue | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/datepicker/Timepicker.vue b/src/datepicker/Timepicker.vue index dc13a34..ec9ea9e 100644 --- a/src/datepicker/Timepicker.vue +++ b/src/datepicker/Timepicker.vue @@ -15,7 +15,7 @@ :ref="item.ref" :class="{ selected: item.selected }" :disabled="!isEnabled(item.date)" - @click="hours=item.value" + @click.stop.prevent="hours=item.value" > {{padStartZero(item.value)}} @@ -27,7 +27,7 @@ :ref="item.ref" :class="{ selected: item.selected }" :disabled="!isEnabled(item.date)" - @click="selectMinutes(item)" + @click.stop.prevent="selectMinutes(item)" > {{padStartZero(item.value)}} @@ -109,6 +109,19 @@ export default defineComponent({ const hours = ref(currentDate.value.getHours()) const minutes = ref(currentDate.value.getMinutes()) + watch(() => props.selected, (value: Date | undefined) => { + let newHours = 0 + let newMinutes = 0 + + if (value) { + newHours = value.getHours() + newMinutes = value.getMinutes() + } + + hours.value = newHours + minutes.value = newMinutes + }) + const hoursList: ComputedRef = computed(() => [...Array(24).keys()].map((value) => ({ value, date: set(new Date(currentDate.value.getTime()), { hours: value, minutes: minutes.value, seconds: 0 }),