From 9d9f2d98a75cc6f8ea9c90d63058657f8bfff022 Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Fri, 25 Mar 2022 14:43:39 -0700 Subject: [PATCH] client: respect reduce motion when auto-scrolling --- client/components/scroll-to-top/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/components/scroll-to-top/index.tsx b/client/components/scroll-to-top/index.tsx index cb7902a0..c470bbc0 100644 --- a/client/components/scroll-to-top/index.tsx +++ b/client/components/scroll-to-top/index.tsx @@ -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) => { // blur the button e.currentTarget.blur() - window.scrollTo({ top: 0, behavior: 'smooth' }) + window.scrollTo({ top: 0, behavior: isReducedMotion ? 'auto' : 'smooth' }) } return (