Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First highlightedItem shows 'null' #223

Open
horakmar opened this issue Jul 4, 2024 · 0 comments
Open

First highlightedItem shows 'null' #223

horakmar opened this issue Jul 4, 2024 · 0 comments

Comments

@horakmar
Copy link

horakmar commented Jul 4, 2024

<Autocomplete bind:highlightedItem={hItem}
...
/>

When you highlight first item in list, hItem is set to null.

It's because highlightIndex is 0 in this expression:

$: highlightedItem =
   filteredListItems &&
   highlightIndex &&
   highlightIndex >= 0 &&
   highlightIndex < filteredListItems.length
     ? filteredListItems[highlightIndex].item
     : null;

I suggest this patch:

diff --git a/src/SimpleAutocomplete.svelte b/src/SimpleAutocomplete.svelte
index 3b27caf..e7275a6 100644
--- a/src/SimpleAutocomplete.svelte
+++ b/src/SimpleAutocomplete.svelte
@@ -344,7 +344,7 @@
 
   $: highlightedItem =
     filteredListItems &&
-    highlightIndex &&
+    highlightIndex !== undefined &&
     highlightIndex >= 0 &&
     highlightIndex < filteredListItems.length
       ? filteredListItems[highlightIndex].item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant