summaryrefslogtreecommitdiffhomepage
path: root/packages/ui/src/hooks/create-auto-scroll.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/ui/src/hooks/create-auto-scroll.tsx')
-rw-r--r--packages/ui/src/hooks/create-auto-scroll.tsx17
1 files changed, 17 insertions, 0 deletions
diff --git a/packages/ui/src/hooks/create-auto-scroll.tsx b/packages/ui/src/hooks/create-auto-scroll.tsx
index e262b7c69..b780f47c6 100644
--- a/packages/ui/src/hooks/create-auto-scroll.tsx
+++ b/packages/ui/src/hooks/create-auto-scroll.tsx
@@ -35,6 +35,22 @@ export function createAutoScroll(options: AutoScrollOptions) {
})
}
+ function forceScrollToBottom() {
+ if (!scrollRef) return
+
+ setStore("userScrolled", false)
+ isAutoScrolling = true
+ if (autoScrollTimeout) clearTimeout(autoScrollTimeout)
+ autoScrollTimeout = setTimeout(() => {
+ isAutoScrolling = false
+ }, 1000)
+
+ scrollRef.scrollTo({
+ top: scrollRef.scrollHeight,
+ behavior: "smooth",
+ })
+ }
+
function handleScroll() {
if (!scrollRef) return
@@ -161,6 +177,7 @@ export function createAutoScroll(options: AutoScrollOptions) {
handleScroll,
handleInteraction,
scrollToBottom,
+ forceScrollToBottom,
userScrolled: () => store.userScrolled,
}
}