From a2807c9815d88febad341e23b55f553e73234c27 Mon Sep 17 00:00:00 2001 From: xiaotianxt Date: Tue, 28 Mar 2023 01:26:49 +0800 Subject: [PATCH] fix(scroll): scroll after click submit button The behavior of SubmitKey and SubmitButton should be the same --- app/components/home.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/components/home.tsx b/app/components/home.tsx index 9c7e45f1..74434eb0 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -204,9 +204,21 @@ export function Chat(props: { showSideBar?: () => void }) { // for auto-scroll const latestMessageRef = useRef(null); + const inputPanelRef = useRef(null); // wont scroll while hovering messages const [autoScroll, setAutoScroll] = useState(false); + useEffect(() => { + const handleMouseDown = (e: MouseEvent) => { + // check if click on input panel + setAutoScroll( + !!inputPanelRef.current && + inputPanelRef.current.contains(e.target as HTMLElement) + ); + }; + document.addEventListener("mousedown", handleMouseDown); + return () => document.removeEventListener("mousedown", handleMouseDown); + }); // preview messages const messages = (session.messages as RenderMessage[]) @@ -369,7 +381,7 @@ export function Chat(props: { showSideBar?: () => void }) { -
+