Skip to content

Commit

Permalink
fix: Fixes clickoutside handler function for issue #1475 (#1476)
Browse files Browse the repository at this point in the history
* fix: Fixes clickoutside handler function for issue #1475

* Update src/lib/datepicker/Datepicker.svelte

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
bmanth60 and coderabbitai[bot] authored Oct 30, 2024
1 parent 351b721 commit 4eda1c2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib/datepicker/Datepicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -249,7 +250,7 @@
}
</script>

<div class="relative {inline ? 'inline-block' : ''}">
<div bind:this={datepickerContainerElement} class="relative {inline ? 'inline-block' : ''}">
{#if !inline}
<div class="relative">
<input bind:this={inputElement} type="text" class="w-full px-4 py-2 text-sm border rounded-md focus:outline-none dark:bg-gray-700 dark:text-white dark:border-gray-600 {getFocusRingClass(color)} {inputClass}" {placeholder} value={range ? `${formatDate(rangeFrom)} - ${formatDate(rangeTo)}` : formatDate(value)} on:focus={() => (isOpen = true)} on:input={handleInputChange} on:keydown={handleInputKeydown} {disabled} {required} aria-haspopup="dialog" />
Expand Down

0 comments on commit 4eda1c2

Please sign in to comment.