fix(date-picker): use calendar.set method to update options

This commit is contained in:
Eric Liu 2022-02-26 10:28:16 -08:00
commit 2ed5343942

View file

@ -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