···1313 select: Date
1414 }>()
15151616- /** Default date to display in picker before value is assigned */
1717- const defaultDate = new Date()
1616+ /** Initial date to show in the calendar when no value is selected */
1717+ export let initialBrowseDate = new Date()
18181919 // inner date value store for preventing value updates (and also
2020 // text updates as a result) when date is unchanged
···39394040 /** Date value */
4141 export let value: Date | null = null
4242- $: store.set(value ? toValidDate(defaultDate, value, min, max, isDisabledDate) : value)
4242+ $: store.set(value ? toValidDate(initialBrowseDate, value, min, max, isDisabledDate) : value)
43434444 /** The earliest value the user can select */
4545- export let min = new Date(defaultDate.getFullYear() - 20, 0, 1)
4545+ export let min = new Date(initialBrowseDate.getFullYear() - 20, 0, 1)
4646 /** The latest value the user can select */
4747- export let max = new Date(defaultDate.getFullYear(), 11, 31, 23, 59, 59, 999)
4747+ export let max = new Date(initialBrowseDate.getFullYear(), 11, 31, 23, 59, 59, 999)
4848 /** Set the input element's ID attribute */
4949 export let id: string | null = null
5050 /** Placeholder text to show when input field is empty */
···7979 const result = parse(text, formatTokens, $store)
8080 if (result.date !== null) {
8181 valid = true
8282- store.set(toValidDate(defaultDate, result.date, min, max, isDisabledDate))
8282+ store.set(toValidDate(initialBrowseDate, result.date, min, max, isDisabledDate))
8383 } else {
8484 valid = false
8585 }
···234234 on:focusout={onFocusOut}
235235 on:select={onSelect}
236236 bind:value={$store}
237237+ {initialBrowseDate}
237238 {min}
238239 {max}
239240 {locale}
+5-5
src/lib/DatePicker.svelte
···46464747 const todayDate = new Date()
48484949- /** Default Date to use */
5050- const defaultDate = new Date()
4949+ /** Initial date to show in the calendar when no value is selected */
5050+ export let initialBrowseDate = new Date()
51515252 /** Show a time picker with the specified precision */
5353 export let timePrecision: 'minute' | 'second' | 'millisecond' | null = null
5454 /** The earliest year the user can select */
5555- export let min = new Date(defaultDate.getFullYear() - 20, 0, 1)
5555+ export let min = new Date(initialBrowseDate.getFullYear() - 20, 0, 1)
5656 /** The latest year the user can select */
5757- export let max = new Date(defaultDate.getFullYear(), 11, 31, 23, 59, 59, 999)
5757+ export let max = new Date(initialBrowseDate.getFullYear(), 11, 31, 23, 59, 59, 999)
5858 /** Disallow specific dates */
5959 export let isDisabledDate: ((dateToCheck: Date) => boolean) | null = null
6060···7272 }
73737474 /** The date shown in the popup when none is selected */
7575- let browseDate = value ? cloneDate(value) : cloneDate(clampDate(defaultDate, min, max))
7575+ let browseDate = value ? cloneDate(value) : cloneDate(clampDate(initialBrowseDate, min, max))
7676 $: setBrowseDate(value)
7777 function setBrowseDate(value: Date | null) {
7878 if (browseDate.getTime() !== value?.getTime()) {
+3
src/routes/DateInput.svelte
···88 let id: string
99 let placeholder: string
1010 let value: Date
1111+ let initialBrowseDate: Date
1112 let min: Date
1213 let max: Date
1314 let valid: boolean
···3334 slot="left"
3435 bind:id
3536 bind:value
3737+ bind:initialBrowseDate
3638 bind:min
3739 bind:max
3840 bind:placeholder
···5153 <svelte:fragment slot="right">
5254 <h3 class="no-top">Props</h3>
5355 <Prop label="value">{value}</Prop>
5656+ <Prop label="initialBrowseDate" bind:value={initialBrowseDate} />
5457 <Prop label="min" bind:value={min} />
5558 <Prop label="max" bind:value={max} />
5659 <Prop label="id" bind:value={id} />
+3
src/routes/DatePicker.svelte
···66 import { hy, de, nb } from 'date-fns/locale'
7788 let value: Date
99+ let initialBrowseDate: Date
910 let min: Date
1011 let max: Date
1112 let locales = [
···2324 <div class="left" slot="left">
2425 <DatePicker
2526 bind:value
2727+ bind:initialBrowseDate
2628 bind:min
2729 bind:max
2830 locale={locale.value}
···3335 <div slot="right">
3436 <h3 class="no-top">Props</h3>
3537 <Prop label="value">{value}</Prop>
3838+ <Prop label="initialBrowseDate" bind:value={initialBrowseDate} />
3639 <Prop label="min" bind:value={min} />
3740 <Prop label="max" bind:value={max} />
3841 <Prop label="locale" bind:value={locale} values={locales} />
+29-27
src/routes/docs/+page.md
···29293030<h3 id="props">Props</h3>
31313232-| Prop | Type | Description |
3333-| :----------------------- | :-------------------------------------------- | :------------------------------------------------------------ |
3434-| `value` | Date \| null | Date value |
3535-| `min` | Date | The earliest value the user can select |
3636-| `max` | Date | The latest value the user can select |
3737-| `placeholder` | string | Placeholder used when date value is null |
3838-| `timePrecision` | "minute" \| "second" \| "millisecond" \| null | Show a time picker with the specified precision |
3939-| `id` | string \| null | Set the input element's ID attribute |
4040-| `valid` | bool | Whether the text is valid |
4141-| `format` | string | Format string |
4242-| `visible` | bool | Whether the date popup is visible |
4343-| `disabled` | bool | Disable the input |
4444-| `required` | bool | Require a value to submit form |
4545-| `closeOnSelection` | bool | Close the date popup when a date is selected |
4646-| `browseWithoutSelecting` | bool | Wait with updating the date until a value is selected |
4747-| `dynamicPositioning` | bool | Dynamically postions the date popup to best fit on the screen |
4848-| `locale` | Locale | Locale object for internationalization |
4949-| `isDisabledDate` | ((dateToCheck: Date) => boolean) \| null | Disallow specific dates |
3232+| Prop | Type | Description |
3333+| :----------------------- | :-------------------------------------------- | :------------------------------------------------------------- |
3434+| `value` | Date \| null | Date value |
3535+| `initialBrowseDate` | Date | Initial date to show in the calendar when no value is selected |
3636+| `min` | Date | The earliest value the user can select |
3737+| `max` | Date | The latest value the user can select |
3838+| `placeholder` | string | Placeholder used when date value is null |
3939+| `timePrecision` | "minute" \| "second" \| "millisecond" \| null | Show a time picker with the specified precision |
4040+| `id` | string \| null | Set the input element's ID attribute |
4141+| `valid` | bool | Whether the text is valid |
4242+| `format` | string | Format string |
4343+| `visible` | bool | Whether the date popup is visible |
4444+| `disabled` | bool | Disable the input |
4545+| `required` | bool | Require a value to submit form |
4646+| `closeOnSelection` | bool | Close the date popup when a date is selected |
4747+| `browseWithoutSelecting` | bool | Wait with updating the date until a value is selected |
4848+| `dynamicPositioning` | bool | Dynamically postions the date popup to best fit on the screen |
4949+| `locale` | Locale | Locale object for internationalization |
5050+| `isDisabledDate` | ((dateToCheck: Date) => boolean) \| null | Disallow specific dates |
50515152<h4 id="format-string">Format string</h4>
5253···69707071<h3 id="datepicker-props">Props</h3>
71727272-| Prop | Type | Description |
7373-| :----------------------- | :-------------------------------------------- | :--------------------------------------------------- |
7474-| `value` | Date \| null | Date value |
7575-| `min` | Date | The earliest year the user can select |
7676-| `max` | Date | The latest year the user can select |
7777-| `timePrecision` | "minute" \| "second" \| "millisecond" \| null | Show a time picker with the specified precision |
7878-| `locale` | Locale | Locale object for internationalization |
7979-| `browseWithoutSelecting` | bool | Wait with updating the date until a date is selected |
8080-| `isDisabledDate` | ((dateToCheck: Date) => boolean) \| null | Disallow specific dates |
7373+| Prop | Type | Description |
7474+| :----------------------- | :-------------------------------------------- | :------------------------------------------------------------- |
7575+| `value` | Date \| null | Date value |
7676+| `initialBrowseDate` | Date | Initial date to show in the calendar when no value is selected |
7777+| `min` | Date | The earliest year the user can select |
7878+| `max` | Date | The latest year the user can select |
7979+| `timePrecision` | "minute" \| "second" \| "millisecond" \| null | Show a time picker with the specified precision |
8080+| `locale` | Locale | Locale object for internationalization |
8181+| `browseWithoutSelecting` | bool | Wait with updating the date until a date is selected |
8282+| `isDisabledDate` | ((dateToCheck: Date) => boolean) \| null | Disallow specific dates |
81838284<h2 id="isDisabledDate">Date disabling example</h2>
8385