Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker undefined 'dayIndex' error for custom date selection (docs out of date?) #2208

Closed
Henco1 opened this issue Sep 16, 2024 · 11 comments · Fixed by #2545
Closed

DatePicker undefined 'dayIndex' error for custom date selection (docs out of date?) #2208

Henco1 opened this issue Sep 16, 2024 · 11 comments · Fixed by #2545
Labels
bug Something isn't working

Comments

@Henco1
Copy link

Henco1 commented Sep 16, 2024

Environment

macOS 14.2.1 (23C71)
node.js v20.9.0
vue v3.5.6.
nuxt v3.13.2
@nuxt/ui v2.18.4
@nuxt/ui-pro v1.4.2
date-fns 4.0.0
v-calendar v3.1.2

Version

2.18.4

Reproduction

  1. Create a custom date component as specified (https://ui.nuxt.com/components/date-picker#daterangepicker)
<script setup lang="ts">
import { DatePicker as VCalendarDatePicker } from 'v-calendar'
import type { DatePickerDate, DatePickerRangeObject } from 'v-calendar/dist/types/src/use/datePicker'
import 'v-calendar/dist/style.css'

const props = defineProps({
  modelValue: {
    type: [Date, Object] as PropType<DatePickerDate | DatePickerRangeObject | null>,
    default: null
  }
})

const emit = defineEmits(['update:model-value', 'close'])

const date = computed({
  get: () => props.modelValue,
  set: (value) => {
    emit('update:model-value', value)
    emit('close')
  }
})

const attrs = {
  transparent: true,
  borderless: true,
  color: 'primary',
  'is-dark': { selector: 'html', darkClass: 'dark' },
  'first-day-of-week': 2,
}
</script>

<template>
  <VCalendarDatePicker v-if="date && (typeof date === 'object')" v-model.range="date" :columns="2" v-bind="{ ...attrs, ...$attrs }" />
  <VCalendarDatePicker v-else v-model="date" v-bind="{ ...attrs, ...$attrs }" />
</template>

<style>
:root {
  --vc-gray-50: rgb(var(--color-gray-50));
  --vc-gray-100: rgb(var(--color-gray-100));
  --vc-gray-200: rgb(var(--color-gray-200));
  --vc-gray-300: rgb(var(--color-gray-300));
  --vc-gray-400: rgb(var(--color-gray-400));
  --vc-gray-500: rgb(var(--color-gray-500));
  --vc-gray-600: rgb(var(--color-gray-600));
  --vc-gray-700: rgb(var(--color-gray-700));
  --vc-gray-800: rgb(var(--color-gray-800));
  --vc-gray-900: rgb(var(--color-gray-900));
}

.vc-primary {
  --vc-accent-50: rgb(var(--color-primary-50));
  --vc-accent-100: rgb(var(--color-primary-100));
  --vc-accent-200: rgb(var(--color-primary-200));
  --vc-accent-300: rgb(var(--color-primary-300));
  --vc-accent-400: rgb(var(--color-primary-400));
  --vc-accent-500: rgb(var(--color-primary-500));
  --vc-accent-600: rgb(var(--color-primary-600));
  --vc-accent-700: rgb(var(--color-primary-700));
  --vc-accent-800: rgb(var(--color-primary-800));
  --vc-accent-900: rgb(var(--color-primary-900));
}
</style>
  1. Create this date range page as specified
<script setup lang="ts">
import { sub, format, isSameDay, type Duration } from 'date-fns'

const ranges = [
  { label: 'Last 7 days', duration: { days: 7 } },
  { label: 'Last 14 days', duration: { days: 14 } },
  { label: 'Last 30 days', duration: { days: 30 } },
  { label: 'Last 3 months', duration: { months: 3 } },
  { label: 'Last 6 months', duration: { months: 6 } },
  { label: 'Last year', duration: { years: 1 } }
]
const selected = ref({ start: sub(new Date(), { days: 14 }), end: new Date() })

function isRangeSelected (duration: Duration) {
  return isSameDay(selected.value.start, sub(new Date(), duration)) && isSameDay(selected.value.end, new Date())
}

function selectRange (duration: Duration) {
  selected.value = { start: sub(new Date(), duration), end: new Date() }
}
</script>

<template>
  <UPopover :popper="{ placement: 'bottom-start' }">
    <UButton icon="i-heroicons-calendar-days-20-solid">
      {{ format(selected.start, 'd MMM, yyy') }} - {{ format(selected.end, 'd MMM, yyy') }}
    </UButton>

    <template #panel="{ close }">
      <div class="flex items-center sm:divide-x divide-gray-200 dark:divide-gray-800">
        <div class="hidden sm:flex flex-col py-4">
          <UButton
            v-for="(range, index) in ranges"
            :key="index"
            :label="range.label"
            color="gray"
            variant="ghost"
            class="rounded-none px-6"
            :class="[isRangeSelected(range.duration) ? 'bg-gray-100 dark:bg-gray-800' : 'hover:bg-gray-50 dark:hover:bg-gray-800/50']"
            truncate
            @click="selectRange(range.duration)"
          />
        </div>

        <DatePicker v-model="selected" @close="close" />
      </div>
    </template>
  </UPopover>
</template>
  1. Click on the 5th of September and then on the 9th of October and witness the error in console logs

Screenshot 2024-09-16 at 15 11 12

Description

Following the daterange section here (https://ui.nuxt.com/components/date-picker#daterangepicker) exactly and then selecting a custom start and end date results in this error:

v-calendar.js?v=4705749a:4740 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'dayIndex')
    at DateRangeContext.render (v-calendar.js?v=4705749a:4740:35)

Additional context

No response

Logs

No response

@Henco1 Henco1 added bug Something isn't working triage labels Sep 16, 2024
@dbaranec
Copy link

i have same problem :/

@srisar
Copy link

srisar commented Sep 18, 2024

The issue is raised here in the v-calendar repo. But no updates yet.
nathanreyes/v-calendar#1498

@remihuigen
Copy link

I'm seeing the same error, though it doesn't break anything in the UI for me

@frasza
Copy link
Contributor

frasza commented Sep 19, 2024

Yeah, issue within v-calendar dep which also seems to be problematic one regarding the updates (last update was from last year)

@aligzl
Copy link

aligzl commented Sep 22, 2024

Did anyone figure it out ?

@DavidDeSloovere
Copy link
Contributor

DavidDeSloovere commented Sep 23, 2024

Did anyone figure it out ?

You can downgrade v-calendar to 3.0, or vue before 3.5

@abarke
Copy link

abarke commented Sep 26, 2024

I ran into the same issue using the example from Nuxt UI DateRangePicker. If you open the console on this page and select a start and end date manually, you will see the error: https://ui.nuxt.com/components/date-picker#daterangepicker

image

@abarke
Copy link

abarke commented Sep 26, 2024

Following silenced it for me:

<VCalendarDatePicker
    ...
    @dayclick="
      (_, event) => {
        event.target.blur();
      }
    " />

Thanks to @akorajac

@iamrevolver
Copy link

Even on their website so)) Is there a solution?

@ddahan ddahan mentioned this issue Oct 13, 2024
7 tasks
@simonmaass
Copy link

we have the following error in sentry: TypeError: undefined is not an object (evaluating 'r[0].dayIndex')
at DateRangeContext.render (../node_modules/v-calendar/dist/es/index.js:3044:33)

@fedetorre
Copy link

I run into the same issue, this is my stacktrace.

runtime-core.esm-bundler.js?v=79afc713:266 Uncaught TypeError: Cannot read properties of undefined (reading 'dayIndex') at DateRangeContext.render (v-calendar.js?v=79afc713:4740:35) at v-calendar.js?v=79afc713:6967:13 at Array.forEach (<anonymous>) at v-calendar.js?v=79afc713:6966:19 at Array.forEach (<anonymous>) at ComputedRefImpl.fn (v-calendar.js?v=79afc713:6965:22) at refreshComputed (reactivity.esm-bundler.js?v=79afc713:334:29) at isDirty (reactivity.esm-bundler.js?v=79afc713:304:68) at refreshComputed (reactivity.esm-bundler.js?v=79afc713:324:65) at isDirty (reactivity.esm-bundler.js?v=79afc713:304:68)

Is there any workaround / solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.