client: respect reduce motion when auto-scrolling

This commit is contained in:
Max Leiter 2022-03-25 14:43:39 -07:00
parent 945d3fbe63
commit 9d9f2d98a7
No known key found for this signature in database
GPG key ID: A3512F2F2F17EBDA

View file

@ -14,10 +14,11 @@ const ScrollToTop = () => {
return () => window.removeEventListener('scroll', handleScroll)
}, [])
const isReducedMotion = typeof window !== 'undefined' ? window.matchMedia('(prefers-reduced-motion: reduce)').matches : false
const onClick = (e: React.MouseEvent<HTMLButtonElement>) => {
// blur the button
e.currentTarget.blur()
window.scrollTo({ top: 0, behavior: 'smooth' })
window.scrollTo({ top: 0, behavior: isReducedMotion ? 'auto' : 'smooth' })
}
return (