mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
fix(date-picker): update calendar if options change (#1128)
Fixes #1127
This commit is contained in:
parent
4eca1cc73c
commit
faeee2b1a1
1 changed files with 22 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue