From 1370818496db1887b894bffa4847f51122c540e7 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Mon, 24 Feb 2025 10:58:50 +1100 Subject: [PATCH] feat: add month navigation functionality to SingleDatePicker component --- src/components/SingleDatePicker.vue | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/components/SingleDatePicker.vue b/src/components/SingleDatePicker.vue index 4fbcd76..97c0d29 100644 --- a/src/components/SingleDatePicker.vue +++ b/src/components/SingleDatePicker.vue @@ -4,17 +4,38 @@ const selectMonth = ref(false) const uniqueId = generateUniqueId() + const currentMonth = ref(new Date().getMonth()) + const currentYear = ref(new Date().getFullYear()) + + function goToLastMonth() { + if (currentMonth.value === 0) { + currentMonth.value = 11 + currentYear.value -= 1 + } else { + currentMonth.value -= 1 + } + } + + function goToNextMonth() { + if (currentMonth.value === 11) { + currentMonth.value = 0 + currentYear.value += 1 + } else { + currentMonth.value += 1 + } + } +