From 82aabc63f55077cd8da1338c17ff17bf4a74df27 Mon Sep 17 00:00:00 2001 From: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> Date: Tue, 12 Mar 2024 20:21:42 +0100 Subject: [PATCH] fix(web): prevent combobox options from disappearing (#7733) --- web/src/lib/components/shared-components/combobox.svelte | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/web/src/lib/components/shared-components/combobox.svelte b/web/src/lib/components/shared-components/combobox.svelte index 80ea3b7965..c69460640b 100644 --- a/web/src/lib/components/shared-components/combobox.svelte +++ b/web/src/lib/components/shared-components/combobox.svelte @@ -24,6 +24,7 @@ export let placeholder = ''; let isOpen = false; + let inputFocused = false; let searchQuery = selectedOption?.label || ''; $: filteredOptions = options.filter((option) => option.label.toLowerCase().includes(searchQuery.toLowerCase())); @@ -36,11 +37,16 @@ const handleClick = () => { searchQuery = ''; isOpen = true; + inputFocused = true; dispatch('click'); }; let handleOutClick = () => { - isOpen = false; + // In rare cases it's possible for the input to still have focus and + // outclick to fire. + if (!inputFocused) { + isOpen = false; + } }; let handleSelect = (option: ComboBoxOption) => { @@ -79,6 +85,7 @@ value={isOpen ? '' : selectedOption?.label || ''} on:input={(e) => (searchQuery = e.currentTarget.value)} on:focus={handleClick} + on:blur={() => (inputFocused = false)} />