mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-21 04:39:19 +00:00
fix(date-picker): use calendar.set method to update options
This commit is contained in:
parent
b8e07c8f08
commit
2ed5343942
1 changed files with 19 additions and 7 deletions
|
@ -139,10 +139,24 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
async function initCalendar(options) {
|
async function initCalendar(options) {
|
||||||
calendar?.destroy();
|
if (calendar) {
|
||||||
calendar = null;
|
calendar.set("minDate", minDate);
|
||||||
|
calendar.set("maxDate", maxDate);
|
||||||
|
calendar.set("locale", locale);
|
||||||
|
calendar.set("dateFormat", dateFormat);
|
||||||
|
Object.entries(flatpickrProps).forEach(([option, value]) => {
|
||||||
|
calendar.set(options, value);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
calendar = await createCalendar({
|
calendar = await createCalendar({
|
||||||
options,
|
options: {
|
||||||
|
...options,
|
||||||
|
appendTo: datePickerRef,
|
||||||
|
defaultDate: $inputValue,
|
||||||
|
mode: $mode,
|
||||||
|
},
|
||||||
base: inputRef,
|
base: inputRef,
|
||||||
input: inputRefTo,
|
input: inputRefTo,
|
||||||
dispatch: (event) => {
|
dispatch: (event) => {
|
||||||
|
@ -196,17 +210,15 @@
|
||||||
$: valueFrom = $inputValueFrom;
|
$: valueFrom = $inputValueFrom;
|
||||||
$: inputValueTo.set(valueTo);
|
$: inputValueTo.set(valueTo);
|
||||||
$: valueTo = $inputValueTo;
|
$: valueTo = $inputValueTo;
|
||||||
$: if ($hasCalendar && inputRef)
|
$: if ($hasCalendar && inputRef) {
|
||||||
initCalendar({
|
initCalendar({
|
||||||
appendTo: datePickerRef,
|
|
||||||
dateFormat,
|
dateFormat,
|
||||||
defaultDate: $inputValue,
|
|
||||||
locale,
|
locale,
|
||||||
maxDate,
|
maxDate,
|
||||||
minDate,
|
minDate,
|
||||||
mode: $mode,
|
|
||||||
...flatpickrProps,
|
...flatpickrProps,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window
|
<svelte:window
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue