fix: survey scroll-to-top on mobile using scrollIntoView

Mobile browsers (iOS Safari especially) ignore window.scrollTo.
Use scrollIntoView on a ref at the top of the page instead,
which works reliably across mobile and desktop browsers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Michael Chihlas
2026-03-07 18:36:04 -05:00
parent b6eaacb9f9
commit 9d9df9f0b8

View File

@@ -186,18 +186,26 @@ export default function SurveyPage() {
}, 0)
const progressPct = Math.round((answeredCount / TOTAL_QUESTIONS) * 100)
const topRef = useRef<HTMLDivElement>(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 (
<div className="min-h-screen bg-background text-foreground">
<div ref={topRef} className="min-h-screen bg-background text-foreground">
<PageMeta
title="Product Survey"
description="Help shape the future of ResolutionFlow by sharing your feedback"