Skip to content

Commit 951727a

Browse files
committed
refactor(events): fix import and date cycling; update readme
1 parent 3b3c977 commit 951727a

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ Try it in the [Svelte REPL](https://svelte.dev/repl/cae0ce6e92634878b6e1a587146d
7878
| theme | The theme name that should be assigned to the theme data-attribute. | `string` (default: `''`)
7979
| presetRanges | The array of present configs to replace the default set with. | `array` (default: [...])
8080

81+
### Events
82+
| Prop | Description | Default |
83+
| :----------------- | :------------------------------------------------------------------------------------ | :-------------------------- |
84+
| onDayClick | Callback function to handle day click events. | `function`
85+
| onNavigationChange | Callback function to handle the navigation click event for months and years | `function`
86+
8187
## Theming
8288
You can customize DatePicker theme using several methods:
8389
- Assign a theme class name via the `theme` property that includes all of your CSS variables overrides

docs/src/examples/range/range.svelte

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
endDate = '';
2828
};
2929
30+
const onNavigationChange = (e) => {
31+
console.log(e, 'onNavigationChange');
32+
};
33+
3034
const toggleDatePicker = () => (isOpen = !isOpen);
3135
const formatDate = (dateString) => dateString && format(new Date(dateString), dateFormat) || '';
3236
@@ -39,12 +43,13 @@
3943
bind:isOpen
4044
bind:startDate
4145
bind:endDate
46+
{onNavigationChange}
4247
isRange
4348
{isMultipane}
4449
{showPresets}
4550
{...$$restProps}
4651
>
47-
<div class="date-field" on:click={toggleDatePicker} class:open={isOpen}>
52+
<div class="date-field" on:click={toggleDatePicker} role="button" tabindex="0" class:open={isOpen}>
4853
<i class="icon-calendar" />
4954
<div class="date">
5055
{#if startDate}
@@ -54,7 +59,7 @@
5459
{/if}
5560
</div>
5661
{#if startDate}
57-
<span on:click={onClearDates}>
62+
<span role="button" tabindex="0" on:click={onClearDates}>
5863
<i class="os-icon-x" />
5964
</span>
6065
{/if}

docs/src/examples/single/single.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@
2525
startDate = new Date(formattedStartDate);
2626
};
2727
28+
const onNavigationChange = (e) => {
29+
console.log(e, 'onNavigationChange');
30+
};
31+
2832
$: formattedStartDate = formatDate(startDate);
2933
</script>
3034

31-
<DatePicker bind:isOpen bind:startDate {...$$props}>
35+
<DatePicker bind:isOpen bind:startDate {...$$props} {onNavigationChange}>
3236
<input type="text" bind:value={formattedStartDate} on:change={onChange} on:click={toggleDatePicker} />
3337
</DatePicker>
3438

src/datepicker.svelte

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script>
22
// @ts-nocheck
3+
import { tick } from 'svelte';
34
import { clickOutside } from './actions';
45
56
/**
@@ -102,7 +103,7 @@
102103
* Callback function to handle the navigation click event for months and years
103104
* @type {(event: Object) => void}
104105
*/
105-
export let onNavigationChange = () => {};
106+
export let onNavigationChange = () => {};
106107
107108
/**
108109
* Indicates whether the date picker should always be shown.
@@ -365,6 +366,11 @@
365366
366367
if (isMultipane) {
367368
month += 1;
369+
370+
if (month > 11) {
371+
month = 1;
372+
}
373+
368374
currentPeriod.end = `${endDateYear}-${month >= 10 ? month : `0${month}`}-${lastDayOfMonth}`;
369375
current = new Date(endDateYear, endDateMonth);
370376
}
@@ -375,7 +381,7 @@
375381
currentPeriod,
376382
isPastPeriod: current < initial
377383
});
378-
}
384+
};
379385
380386
/**
381387
* Handles the "to previous month" action in the date picker.

0 commit comments

Comments
 (0)