Skip to content

Commit

Permalink
fix value setting from initialDate and add rich change event, close #127
Browse files Browse the repository at this point in the history
  • Loading branch information
mskocik committed Sep 30, 2023
1 parent 18b0a98 commit 7606922
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/documentation/06-events/page.svx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@
title: Events
---

Component emits `input`, `change` and `blur` events.
Component emits `input`, `change`, `dateChange` and `blur` events.

- `input` is dispatched on `<input>` element therefore you can get current value like from every native event:
- `change` event is using Svelte's `eventDispatcher`, therefore triggered event contains `detail` property
- `dateChange` event is dispatched on date change as well as `change` event, but with more data on `detail` property:

```js
{ // event.detail property
value: string | string[] | null // array for range
dateValue: Date | Date[] | null // array for range
displayValue: string
valueFormat: string
displayFormat: string
}
```

For custom element:

Expand Down
9 changes: 9 additions & 0 deletions src/lib/components/SveltyPicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
const dispatch = createEventDispatcher();
let { valueArray, prevValue, innerDates } = initProps(value, initialDate, format, i18n, formatType);
// properly set value from initialDate
if (!value && initialDate) value = isRange ? valueArray : valueArray[0];
let currentFormat = format;
let isFocused = pickerOnly;
let undoHistory = [...valueArray];
Expand Down Expand Up @@ -325,6 +327,13 @@
isDirty = computeDirty(valueArray);
dispatchInputEvent(true);
dispatch("change", isRange ? valueArray : (valueArray[0] || null)); // change is dispatched on user interaction
dispatch("dateChange", {
value: isRange ? valueArray : (valueArray[0] || null),
dateValue: isRange ? innerDates : (innerDates[0] || null),
displayValue: displayValue,
valueFormat: format,
displayFormat: displayFormat
});
doResetView && resetView();
}
Expand Down

0 comments on commit 7606922

Please sign in to comment.