diff --git a/frontend/src/pages/SurveyPage.tsx b/frontend/src/pages/SurveyPage.tsx index acb8e5ce..bc25bd2c 100644 --- a/frontend/src/pages/SurveyPage.tsx +++ b/frontend/src/pages/SurveyPage.tsx @@ -186,18 +186,26 @@ export default function SurveyPage() { }, 0) const progressPct = Math.round((answeredCount / TOTAL_QUESTIONS) * 100) + const topRef = useRef(null) + const goSlide = (idx: number) => { setCurrentSlide(idx) } - // Scroll to top whenever the active slide changes + // Scroll to top whenever the active slide changes — mobile browsers + // (especially iOS Safari) ignore window.scrollTo, so we use + // scrollIntoView on a ref at the top of the page as primary method const isFirstRender = useRef(true) useEffect(() => { if (isFirstRender.current) { isFirstRender.current = false return } - window.scrollTo({ top: 0, behavior: 'smooth' }) + if (topRef.current) { + topRef.current.scrollIntoView({ behavior: 'smooth', block: 'start' }) + } else { + window.scrollTo({ top: 0, behavior: 'smooth' }) + } }, [currentSlide]) const handleSubmit = async () => { @@ -296,7 +304,7 @@ export default function SurveyPage() { } return ( -
+