diff --git a/src/lib/datepicker/Datepicker.svelte b/src/lib/datepicker/Datepicker.svelte index 8e4aa5e6d..1d83c756c 100644 --- a/src/lib/datepicker/Datepicker.svelte +++ b/src/lib/datepicker/Datepicker.svelte @@ -25,6 +25,7 @@ const dispatch = createEventDispatcher(); let isOpen: boolean = inline; let inputElement: HTMLInputElement; + let datepickerContainerElement: HTMLDivElement; let currentMonth: Date = value || defaultDate || new Date(); let focusedDate: Date | null = null; let calendarRef: HTMLDivElement; @@ -150,7 +151,7 @@ } function handleClickOutside(event: MouseEvent) { - if (isOpen && !inputElement.contains(event.target as Node)) { + if (isOpen && datepickerContainerElement && !datepickerContainerElement.contains(event.target as Node)) { isOpen = false; } } @@ -249,7 +250,7 @@ } -
+
{#if !inline}
(isOpen = true)} on:input={handleInputChange} on:keydown={handleInputKeydown} {disabled} {required} aria-haspopup="dialog" />