From bf681ae913961fefa727bcfa23c99ff449de4ea3 Mon Sep 17 00:00:00 2001 From: liangfung <1098486429@qq.com> Date: Thu, 23 May 2024 10:58:13 +0800 Subject: [PATCH] fix(ui): scroll to bottom when a request is sent --- ee/tabby-ui/components/chat/chat.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ee/tabby-ui/components/chat/chat.tsx b/ee/tabby-ui/components/chat/chat.tsx index edf172f2c58f..f3c8547276e1 100644 --- a/ee/tabby-ui/components/chat/chat.tsx +++ b/ee/tabby-ui/components/chat/chat.tsx @@ -228,6 +228,23 @@ function ChatRenderer( }) }, [answer, isLoading]) + React.useLayoutEffect(() => { + // scroll to bottom when a request is sent + if (isLoading) { + if (container) { + container.scrollTo({ + top: container.scrollHeight, + behavior: 'smooth' + }) + } else { + window.scrollTo({ + top: document.body.offsetHeight, + behavior: 'smooth' + }) + } + } + }, [isLoading]) + React.useEffect(() => { if (error && qaPairs?.length) { setQaPairs(prev => {