From 7bfab65042c0eb97c6872ebf2965de88d2001696 Mon Sep 17 00:00:00 2001 From: Lemon Date: Fri, 27 Mar 2026 12:46:59 -0700 Subject: [PATCH] Fix toast swipe direction to match entry direction on mobile On mobile, toasts enter from the top but previously could only be swiped right to dismiss. Now swipe direction is responsive: swipe up on mobile (top-positioned), swipe right on desktop (bottom-right positioned). Exit animations also match the swipe direction at each breakpoint. --- src/components/ui/toast.tsx | 13 +++++++++++-- src/components/ui/toaster.tsx | 15 ++++++++++++++- src/hooks/useIsMobile.tsx | 4 +++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/components/ui/toast.tsx b/src/components/ui/toast.tsx index 5a6dc996..0c861e2d 100644 --- a/src/components/ui/toast.tsx +++ b/src/components/ui/toast.tsx @@ -14,7 +14,7 @@ const ToastViewport = React.forwardRef< = MD_BREAKPOINT) + + useEffect(() => { + const mql = window.matchMedia(`(min-width: ${MD_BREAKPOINT}px)`) + const onChange = () => setIsMdScreen(mql.matches) + mql.addEventListener("change", onChange) + return () => mql.removeEventListener("change", onChange) + }, []) return ( - + {toasts.map(function ({ id, title, description, action, ...props }) { return ( diff --git a/src/hooks/useIsMobile.tsx b/src/hooks/useIsMobile.tsx index 0fae2179..b6194015 100644 --- a/src/hooks/useIsMobile.tsx +++ b/src/hooks/useIsMobile.tsx @@ -1,6 +1,8 @@ import { useEffect, useState } from "react" -const MOBILE_BREAKPOINT = 768; +import tailwindConfig from "../../tailwind.config" + +const MOBILE_BREAKPOINT = parseFloat(tailwindConfig.theme.screens.md); export function useIsMobile(): boolean { const [isMobile, setIsMobile] = useState(window.innerWidth < MOBILE_BREAKPOINT);