Skip to content

Calendar with year dropdown: Cannot read properties of undefined (reading 'label') #2269

@Coronon

Description

@Coronon

Describe the bug

When using the Calendar component with the year selector dropdown, going to the last selectable year and month and using the right arrow to go to the next month (and year) an error will be thrown and the component stops functioning. This seems to be caused by the calendar-year-select.svelte component trying to read selectedYearItem.label in {yearItems.find((item) => item.value === value)?.label || selectedYearItem.label} where selectedYearItem is undefined.

Image

Reproduction

https://shadcn-svelte.com/docs/components/calendar

Go to December 2035 and click the right arrow to go to January 2036 -> error!

Image

Logs

Uncaught TypeError: Cannot read properties of undefined (reading 'label')

	in <unknown>
	in calendar-year-select.svelte
	in calendar-year-select.svelte
	in calendar-caption.svelte
	in calendar-header.svelte
	in calendar-header.svelte
	in calendar-month.svelte
	in calendar-months.svelte
	in calendar.svelte
	in calendar.svelte
	in ...

System Info

System:
    OS: macOS 15.6
    CPU: (12) arm64 Apple M2 Max
    Memory: 6.73 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.6.0 - /opt/homebrew/bin/node
    npm: 11.5.1 - /opt/homebrew/bin/npm
    pnpm: 10.14.0 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 138.0.7204.184
    Safari: 18.6

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    under reviewFurther discussion is needed to determine this issue's scope and/or implementation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions