Closed nika-d closed 3 years ago
pull request for fix: https://github.com/pstanoev/simple-svelte-autocomplete/pull/113
Hi @nika-d, the described behavior is intended. There are other components which filters the list to single item after selection. This component was envisioned like the standard
Hi @pstanoev,
thanks for your quick reaction!
And I am very sorry for the formatting! This was my first pull request to another repo, and the blunder wont happen again.
There seems to be a missunderstanding. You wrote: "There are other components which filters the list to single item after selection." -> But for the case, that items and selectedItem are both changed in the same tick, the filtering happens before the selection.
The pull request was more change than the formatting. It is about the order of reactive $: statements.
Without the change the control flow was:
...
line 181 $: selectedItem, onSelectedItemChanged(); // filter options list - the old one! <- wrong!
...
line 299 $: items, prepareListItems(); // set the new options list
The change in the pull request:
...
line 275 $: items, prepareListItems(); // set the new options list
...
line 285 $: selectedItem, onSelectedItemChanged(); // filter the new options list
May I open a new pull request for the fix?
Best regards Nika
Thanks again, the change is now published.
Unexpected behavior: Let´s say, the autocomplete was already rendered once, with some list of possible choices in
items
. Everything fine so far. Now, when we change theselectedItem
and theitems
, and then click into the autocomplete field, we see: autocomplete still uses the old value for the options! Also, as checked in Svelte Dev Tools, internal variablefilteredListItems
still shows the old items list, whilelistItems
already hold new value. Here is a minimal example highlighting the weird behavior: https://github.com/nika-d/autocomplete-minimal-example Desired behavior: Whenitems
is set to a new array, this new options list shows up the very next time the autocomplete options dropdown opens. Maybe related: Just observed, that also the event handlers are not called properly as expected.@pstanoev Hi! 🙂 Could you please verify, if this is a bug or a feature? Or maybe it´s just my wrong usage..? (You are invited as collaborator just in case you want to correct the example. )