From a5ffc53e25dbde8cc102109c2073fc254e2dd0ff Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 22 Apr 2025 18:49:29 +0530 Subject: [PATCH] add smooth scrolling to chat --- gui/src/pages/gui/useAutoScroll.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gui/src/pages/gui/useAutoScroll.ts b/gui/src/pages/gui/useAutoScroll.ts index a787e7ec9..633201683 100644 --- a/gui/src/pages/gui/useAutoScroll.ts +++ b/gui/src/pages/gui/useAutoScroll.ts @@ -9,6 +9,17 @@ export const useAutoScroll = ( useEffect(() => { if (history.length) { setUserHasScrolled(false); + if (ref.current) { + // smooth scroll to the bottom of the chat + ref.current.style.scrollBehavior = "smooth"; + ref.current.scrollTop = ref.current.scrollHeight; + + // use 100 ms delay to scroll to restore the scroll and wait for the chat to be scrolled + const timer = setTimeout(() => { + ref.current!.style.scrollBehavior = "auto"; + clearTimeout(timer); + }, 100); + } } }, [history.length]);