icehaunter / vue3-datepicker

Simple datepicker component for Vue 3
https://icehaunter.github.io/vue3-datepicker/
MIT License
150 stars 153 forks source link

Date not changing when minimumView set to 'time' #86

Closed khems closed 1 year ago

khems commented 2 years ago

If minimumView is set to 'time' and pageDate is already set, changing the date through the date picker only allows changes of time.

Steps to reproduce:

<datepicker
 v-model="pickerStartDate"
 :inputFormat="dd/MM/yyyy HH:mm"
 minimumView="time"
/>

Select a date and time - first selection works. Then select another and it'll keep the date the same and not change the time.

Fix

I've isolated the problem to https://github.com/icehaunter/vue3-datepicker/blob/9f21b007ccc4f5f61f2181f9548735d14aac2f38/src/datepicker/Timepicker.vue#L107

--- a/src/datepicker/Timepicker.vue
+++ b/src/datepicker/Timepicker.vue
@@ -104,7 +104,7 @@ export default defineComponent({
     const hoursListRef = ref(null as HTMLElement | null)
     const minutesListRef = ref(null as HTMLElement | null)

-    const currentDate = computed(() => props.selected ?? props.pageDate)
+    const currentDate = computed(() => props.pageDate ?? props.selected)

     const hours = ref(currentDate.value.getHours())
     const minutes = ref(currentDate.value.getMinutes())

props.selected and props.pageDate are the wrong way around.

I've submitted a pull request to fix this https://github.com/icehaunter/vue3-datepicker/pull/87