diff --git a/src/components/ChatBot.jsx b/src/components/ChatBot.jsx
index 508248b..4460028 100644
--- a/src/components/ChatBot.jsx
+++ b/src/components/ChatBot.jsx
@@ -15,18 +15,64 @@ const ChatBot = () => {
const buttonRef = useRef(null);
const messagesEndRef = useRef(null);
const inputRef = useRef(null);
+ const messagesContainerRef = useRef(null);
- // Auto-scroll to bottom when new messages arrive
- useEffect(() => {
+ // Scroll to bottom helper
+ const scrollToBottom = () => {
if (messagesEndRef.current) {
messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
}
+ };
+
+ // Auto-scroll to bottom when new messages arrive
+ useEffect(() => {
+ scrollToBottom();
}, [messages]);
- // Focus input when chat opens
+ // Scroll to bottom when chat opens
+ useEffect(() => {
+ if (isOpen) {
+ // Small delay to ensure DOM is rendered
+ setTimeout(scrollToBottom, 100);
+ if (inputRef.current) {
+ inputRef.current.focus();
+ }
+ }
+ }, [isOpen]);
+
+ // Prevent scroll propagation to body
useEffect(() => {
- if (isOpen && inputRef.current) {
- inputRef.current.focus();
+ const messagesContainer = messagesContainerRef.current;
+
+ if (isOpen && messagesContainer) {
+ const preventScroll = (e) => {
+ e.stopPropagation();
+ };
+
+ messagesContainer.addEventListener("wheel", preventScroll, {
+ passive: true,
+ });
+ messagesContainer.addEventListener("touchmove", preventScroll, {
+ passive: true,
+ });
+
+ return () => {
+ messagesContainer.removeEventListener("wheel", preventScroll);
+ messagesContainer.removeEventListener("touchmove", preventScroll);
+ };
+ }
+ }, [isOpen]);
+
+ // Prevent body scroll when chat is open
+ useEffect(() => {
+ if (isOpen) {
+ // Store original overflow
+ const originalOverflow = document.body.style.overflow;
+ document.body.style.overflow = "hidden";
+
+ return () => {
+ document.body.style.overflow = originalOverflow;
+ };
}
}, [isOpen]);
@@ -100,181 +146,205 @@ const ChatBot = () => {
};
return (
-
- {/* Chat Toggle Button */}
-
-
- {/* Chat Window */}
+ <>
+ {/* Overlay for mobile */}
{isOpen && (
setIsOpen(false)}
+ />
+ )}
+
+
+ {/* Chat Toggle Button */}
+