virtua icon indicating copy to clipboard operation
virtua copied to clipboard

Method to stick to bottom of scroller as content increases

Open mirshko opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

Instead of requiring to scroll to last item in the index each time the content changes, it would be nice if there was a built in method which would automatically stick to the bottom of the virtualised scroll section as content changes.

Describe the solution you'd like

Either a method / prop on the component stickToBottom or an api method that can be toggled.

Describe alternatives you've considered

useEffect on data length and scroll to last in index whenever it changes.

mirshko avatar Dec 16 '24 18:12 mirshko

There are many ways to do this poorly, but for something "flicker free" you need to directly access the scrolling element (parent of the Virtualizer. The scrollRef).

Watch for changes to the scrolling element with a MutationObserver then set el.scrollTop = el.scrollHeight.

Use virtua and react APIs sparingly, any delay (async etc) will introduce flickering.

arenasys avatar Jan 05 '25 15:01 arenasys

Basically, we will not add any APIs specific to chat use case to virtua.

onResizeViewport like prop might be added in #301 and #408, if the event hook is appropriate.

And also I can recommend chat-viewer for chat. It seems to be built on virtua for now, and it has followAtBottom API.

inokawa avatar Oct 18 '25 04:10 inokawa

Alright great!

We use this for a fast updating logs viewer that takes updates from an eventstream but will give these a shot, thank you.

mirshko avatar Oct 18 '25 06:10 mirshko