Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/components/BackToTopButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@ export default function BackToTopButton() {
}
};

const [prefersReducedMotion, setPrefersReducedMotion] = useState(false);

useEffect(() => {
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
setPrefersReducedMotion(mq.matches);
const handler = (e: MediaQueryListEvent) => setPrefersReducedMotion(e.matches);
mq.addEventListener("change", handler);
return () => mq.removeEventListener("change", handler);
}, []);

const scrollToTop = () => {
if (typeof window !== "undefined") {
window.scrollTo({
top: 0,
behavior: "smooth",
behavior: prefersReducedMotion ? "auto" : "smooth",
});
}
};
Expand Down Expand Up @@ -70,7 +80,7 @@ export default function BackToTopButton() {
strokeDasharray={circumference}
strokeDashoffset={strokeDashoffset}
style={{ filter: "drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 60%, transparent))" }}
className="transition-[stroke-dashoffset] duration-100"
className={`transition-[stroke-dashoffset] duration-100 ${prefersReducedMotion ? "!transition-none" : ""}`}
/>
</svg>
<button
Expand Down
Loading