sveltejs / svelte-virtual-list

A virtual list component for Svelte apps
https://svelte.dev/repl/f78ddd84a1a540a9a40512df39ef751b
Other
689 stars 58 forks source link

Viewport goes empty if scrolled down and items array changes. #30

Open kevmodrome opened 5 years ago

kevmodrome commented 5 years ago

So I decided to try to work with this component and add a filteredItems function that filters depending on some input.

It appears as though the viewport is not scrolled to the top when the items array changes which results in some weird behaviour. I have showcased it in this REPL

To reproduce, scroll down some hundreds of items and start writing something in the input field.

The solution is simple and I will make a PR.

jdevine commented 4 years ago

I mucked about some and saw that a change to items was running refresh but relying on stale info, so I made the change to items reset start and end if they are now out of range. There may be some duplicate calls going on, but as a quick and dirty it seems to work:

REPL