Skip to content

Commit b6c32e3

Browse files
committed
Implement auto scroll
1 parent ae6fca1 commit b6c32e3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/components/ChatSection.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from "react";
1+
import { useState, useEffect, useRef } from "react";
22
import { Button } from "@/components/ui/button";
33
import { Input } from "@/components/ui/input";
44
import { ArrowRight, Bot, AlertCircle } from "lucide-react";
@@ -25,6 +25,15 @@ const ChatSection = () => {
2525
const [inputValue, setInputValue] = useState("");
2626
const [isLoading, setIsLoading] = useState(false);
2727
const [isServerOnline, setIsServerOnline] = useState(true);
28+
const messagesEndRef = useRef<HTMLDivElement>(null);
29+
30+
const scrollToBottom = () => {
31+
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
32+
};
33+
34+
useEffect(() => {
35+
scrollToBottom();
36+
}, [messages]);
2837

2938
const predefinedQuestions = [
3039
"What is your background?",
@@ -164,6 +173,7 @@ const ChatSection = () => {
164173
</div>
165174
</div>
166175
)}
176+
<div ref={messagesEndRef} />
167177
</div>
168178

169179
{/* Input Area */}

0 commit comments

Comments
 (0)