From b57e1157354558063c37b584123dd7b071c4b7b0 Mon Sep 17 00:00:00 2001 From: Nimit Sharma <91617550+ABUDIYAAAA@users.noreply.github.com> Date: Thu, 30 Oct 2025 13:04:19 +0530 Subject: [PATCH] fix responsive Signed-off-by: Nimit Sharma <91617550+ABUDIYAAAA@users.noreply.github.com> --- src/components/ChatBot.jsx | 376 ++++++++++++++++++++++--------------- 1 file changed, 223 insertions(+), 153 deletions(-) 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 ( -