Skip to content

Commit

Permalink
fix(web): prevent combobox options from disappearing (#7733)
Browse files Browse the repository at this point in the history
  • Loading branch information
michelheusschen committed Mar 12, 2024
1 parent 17d7d93 commit 82aabc6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion web/src/lib/components/shared-components/combobox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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) => {
Expand Down Expand Up @@ -79,6 +85,7 @@
value={isOpen ? '' : selectedOption?.label || ''}
on:input={(e) => (searchQuery = e.currentTarget.value)}
on:focus={handleClick}
on:blur={() => (inputFocused = false)}
/>

<div
Expand Down

0 comments on commit 82aabc6

Please sign in to comment.