Radix UI Toast Swipe to Dismiss Not Working — Fix Gesture
In this fix, you'll learn how to enable swipe-to-dismiss on Radix UI Toasts. This matters for mobile-friendly notification dismiss, and appears in notification systems and alert components.
The Problem
The following code demonstrates the typical mistake:
<Toast>
<ToastTitle>Notification</ToastTitle>
<ToastDescription>You have a new message</ToastDescription>
</Toast>
// Swiping doesn't dismiss the toast
The Fix
Here is the corrected version:
<Toast
swipeDirection="right"
swipeThreshold={50}
>
<div className="flex items-start gap-3">
<div className="flex-1">
<ToastTitle>Notification</ToastTitle>
<ToastDescription>You have a new message</ToastDescription>
</div>
<ToastClose />
</div>
</Toast>
// Swiping right dismisses the toast with animation
Prevention
- Set swipeDirection to 'right', 'left', 'up', 'down', or multiple: ['right', 'left'].
- swipeThreshold controls how far the user must swipe (in pixels) before dismiss triggers.
- Combine with AnimatePresence for smooth swipe-out animation.
- onSwipeEnd callback fires when the swipe gesture completes.
- ToastClose button still works alongside swipe gesture.
Common Mistakes with ui toast swipe
- Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad - Mixing let bindings with <- bindings in do notation, producing type errors
These mistakes appear frequently in real-world RADIX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro