Skip to content

Commit

Permalink
fix(datepicker): fix date error
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaubree committed Dec 13, 2023
1 parent 80ad3c9 commit 01eb50a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/datepicker/UDatepicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const props = withDefaults(defineProps<{
ui: () => useAppUi().datepicker,
})
const date = defineModel<Date | null>()
const date = defineModel<Date | string | null>()
const years = ref<Array<number>>([])
const currentSelection = ref<DateType>()
Expand Down Expand Up @@ -81,7 +81,7 @@ function isToday(date: number): boolean {
return today === d
}
function isSelectedDate(d: number) {
return date.value?.toDateString() === new Date(year.value, month.value, d).toDateString()
return date.value && new Date(date.value).toDateString() === new Date(year.value, month.value, d).toDateString()
}
function onPreviousButtonClick() {
if (currentSelection.value === 'day') {
Expand Down Expand Up @@ -170,7 +170,7 @@ onMounted(() => {
<template>
<UPopover :popper="popper">
<slot>
<UButton color="pilot" :icon="icon" :label="label || date?.toLocaleDateString() || 'Select date'">
<UButton color="pilot" :icon="icon" :label="label || date ? new Date(date as Date | string)?.toLocaleDateString() : 'Select date'">
<template v-if="date && isClearable" #trailing>
<UTooltip :text="clearLabel || 'Clear date'" :popper="{ placement: 'right' }" :ui="{ transition: config.tooltip.transition }">
<UIcon :name="config.default.closeIcon" @click.stop="date = undefined" />
Expand Down

0 comments on commit 01eb50a

Please sign in to comment.