fix(date-picker): update calendar if options change (#1128)

Fixes #1127
This commit is contained in:
metonym 2022-02-26 11:24:44 -08:00 committed by GitHub
commit faeee2b1a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -138,17 +138,24 @@
},
});
async function initCalendar() {
async function initCalendar(options) {
if (calendar) {
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({
options: {
...options,
appendTo: datePickerRef,
dateFormat,
defaultDate: $inputValue,
locale,
maxDate,
minDate,
mode: $mode,
...flatpickrProps,
},
base: inputRef,
input: inputRefTo,
@ -203,7 +210,15 @@
$: valueFrom = $inputValueFrom;
$: inputValueTo.set(valueTo);
$: valueTo = $inputValueTo;
$: if ($hasCalendar && !calendar && inputRef) initCalendar();
$: if ($hasCalendar && inputRef) {
initCalendar({
dateFormat,
locale,
maxDate,
minDate,
...flatpickrProps,
});
}
</script>
<svelte:window