diff --git a/adventure-rental-app/src/ChatbotPage.jsx b/adventure-rental-app/src/ChatbotPage.jsx index 316f7af..19ee6df 100644 --- a/adventure-rental-app/src/ChatbotPage.jsx +++ b/adventure-rental-app/src/ChatbotPage.jsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect, useRef } from 'react'; import { FiCamera, FiSend, FiUser } from 'react-icons/fi'; const ChatbotPage = () => { @@ -7,6 +7,17 @@ const ChatbotPage = () => { ]); const [inputMessage, setInputMessage] = useState(''); const [isTyping, setIsTyping] = useState(false); + const messagesEndRef = useRef(null); + + const scrollToBottom = () => { + setTimeout(() => { + messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); + }, 0); + }; + + useEffect(() => { + scrollToBottom(); + }, [messages, isTyping]); const handleSendMessage = () => { if (inputMessage.trim() === '') return; @@ -92,6 +103,7 @@ const ChatbotPage = () => { )} +
{/* Input Area */}