diff --git a/frontend/src/lib/components/Energy/EmptyFoodComp.svelte b/frontend/src/lib/components/Energy/EmptyFoodComp.svelte index bcea3f3..13e2297 100644 --- a/frontend/src/lib/components/Energy/EmptyFoodComp.svelte +++ b/frontend/src/lib/components/Energy/EmptyFoodComp.svelte @@ -117,6 +117,18 @@ autocompleteList.style.left = `${left}px`; } } + + let timeout: number; + function handleFocusOut() { + timeout = setTimeout(() => { + foodSearch = []; + }, 100); + } + + function handleFocusIn() { + clearTimeout(timeout); + updateAutocomplete(); + } @@ -136,8 +148,8 @@ contenteditable="true" autofocus on:keydown={update} - on:focusin={updateAutocomplete} - on:focusout={() => foodSearch = []} + on:focusin={handleFocusIn} + on:focusout={handleFocusOut} bind:this={nameElement} />