From 681d528c9eccb049d04928b564f65c717f496698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoni=20Nu=C3=B1ez=20Romeu?= Date: Fri, 13 Mar 2026 10:59:46 +0100 Subject: [PATCH] Hotfix scroll up when submit form --- src/components/BookingSection.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/BookingSection.tsx b/src/components/BookingSection.tsx index 5dfb736..37b5302 100644 --- a/src/components/BookingSection.tsx +++ b/src/components/BookingSection.tsx @@ -45,6 +45,7 @@ const BookingSection = () => { const [showCountryDropdown, setShowCountryDropdown] = useState(false); const countryDropdownRef = useRef(null); const countryInputRef = useRef(null); + const sectionRef = useRef(null); // Generate unique requestId on component mount useEffect(() => { const uniqueId = `REQ-${Date.now()}-${Math.floor(Math.random() * 10000)}`; @@ -107,6 +108,13 @@ const BookingSection = () => { return () => document.removeEventListener('mousedown', handleClickOutside); }, [showCountryDropdown]); + // Ensure the booking section stays in view when status changes (e.g., after submit) + useEffect(() => { + if (status === "success" || status === "error") { + sectionRef.current?.scrollIntoView({ behavior: "smooth", block: "start" }); + } + }, [status]); + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setErrors({}); @@ -141,7 +149,7 @@ const BookingSection = () => { if (status === "success") { return ( -
+
{ } return ( -
+