sveltejs / svelte-virtual-list

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

[group] control scroll position #43

Open gitbreaker222 opened 4 years ago

gitbreaker222 commented 4 years ago

This is a summary of issues around similar use-cases:

I hope the use-case-namings are helpful - all these issues have in common, that we expect certain behaviours from the scroll position. To prevent solving one issue while re-creating another, I suggest to work towards one PR that solves them together :bullettrain_side: :handshake:

REPL: https://svelte.dev/repl/1c36db7c1e7e4ef2bfb04874321412e5?version=3.20.1


comparable vanilla implementations:

gitbreaker222 commented 4 years ago

attempting to create a "scrollTo" method, that scrolls an element by index at start, if list borders not hit. Problems so far:

gitbreaker222 commented 4 years ago

solved problems to this point:

tested in firefox

gitbreaker222 commented 4 years ago

update: after almost giving up fixing the remaining issue (adjust scroll position when filter list) I finally solved it! The demo has been updated and next I'd like to do a PR with clean code

So @Rich-Harris maybe now is a good time to get your attention :) My proposal:

Any thoughts before I start coding?

gitbreaker222 commented 4 years ago

Here is a webm of the demo :angel: https://windtanz.windcloud.de/index.php/s/d43AbLtXw9mimj9

rsousacode commented 3 years ago

Very nice. Thanks! Apparently your _scrollTo3 solves my problem!! 👍 https://github.com/sveltejs/svelte-virtual-list/issues/50

Metis77 commented 3 years ago

great work! REPL: https://svelte.dev/repl/1c36db7c1e7e4ef2bfb04874321412e5?version=3.20.1 should be merged.

gitbreaker222 commented 3 years ago

I am preparing a pull request. Fork, cleanup, testing is done. One issue remains in logs:

"<VirtualList> was created with unknown prop 'scrollToIndex'"

How to properly expose a function / "method" so it can be called from outside? I played with bind: let: use: but don't get it :/

update: bam got it - the consumer of binds to the exposed function scrollToIndex. Outside I've initialized a same named variable to bind to ... with a noop function

<script>
    export let scrollToIndex = () => {} // this should be "undefined"
</script>

<div class="List">
    <VirtualList {items}
        bind:start
        bind:end
        bind:scrollToIndex
        let:item
        >
        <ListItem {item}/>
    </VirtualList>
</div>

initializing with explicit undefined is correct https://stackoverflow.com/a/58574086/3313410 - thx @Rich-Harris

updating demo and opening PR shortly :eyes:

gitbreaker222 commented 2 years ago

:information_source: published fork https://www.npmjs.com/package/svelte-virtual-list-ce