Skip to content

Commit

Permalink
autoscroll only if not already scrolled up by a 200px margin (#1574)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainpolletvillard authored Mar 15, 2024
1 parent 8c6b521 commit ef717ea
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/public/src/pages/component/chat/chat-history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ export default function ChatHistory(props: { source: string }) {
const domRef = useRef<HTMLDivElement>(null)

useEffect(() => {
if (messages.length > 0 && domRef && domRef.current) {
if (
messages.length > 0 &&
domRef &&
domRef.current &&
domRef.current.scrollTop + domRef.current.clientHeight >=
domRef.current.scrollHeight - 200 // autoscroll only if not already scrolled up by a 200px margin
) {
domRef.current.scrollTop = domRef.current.scrollHeight
}
}, [messages.length])
Expand Down

0 comments on commit ef717ea

Please sign in to comment.