Skip to content

🐛 startDate overrides defaultYear / defaultMonth #46

Open
@oscarhermoso

Description

@oscarhermoso

Describe the bug

When both startDate and defaultYear / defaultMonth are defined, then defaultYear / defaultMonth is ignored.

I understand that this might be expected behaviour, but currently, there is no way to specify a startDate and also set the defaultMonth / defaultYear to a different value.

To Reproduce
Steps to reproduce the behavior:

  1. Set up a date picker with below code:
<!-- src/routes/book-appointment/[[date]]+page.svelte -->

<script lang="ts">
	import { page } from '$app/stores';

	let selectedDate = $page.params.date ? new Date($page.params.date) : undefined;
	let defaultDate = $page.url.searchParams.has('viewFrom') ? new Date($page.params.get('viewFrom')) : undefined;
</script>

<DatePicker
	bind:startDate={selectedDate}
	showYearControls={false}
	defaultYear={defaultDate?.getFullYear()}
	defaultMonth={defaultDate?.getMonth()}
	isOpen={true}
	alwaysShow={true}
	enableFutureDates={true}
	enablePastDates={false}
/>
  1. Go to URL http://localhost:5173/book-appointment/2024-03-15?viewFrom=2025-06-01

Expected behavior

I expect the calendar to show the month of June, and if I navigate back to June, then the 15th of March will be selected.

Actual behavior

The calendar shows the month of March, with the 15th of March selected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions