fix: prevent toast interaction from affecting dialog

Add event stopping to Toast root and close button to prevent leaks

Co-authored-by: Simon <85533298+handsomezhuzhu@users.noreply.github.com>
This commit is contained in:
v0
2026-02-04 16:21:49 +00:00
parent 94af84288b
commit 22d3209fc6

View File

@@ -44,11 +44,19 @@ const Toast = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Root>, React.ElementRef<typeof ToastPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> & React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
VariantProps<typeof toastVariants> VariantProps<typeof toastVariants>
>(({ className, variant, ...props }, ref) => { >(({ className, variant, onPointerDown, onMouseDown, ...props }, ref) => {
return ( return (
<ToastPrimitives.Root <ToastPrimitives.Root
ref={ref} ref={ref}
className={cn(toastVariants({ variant }), className)} className={cn(toastVariants({ variant }), className)}
onPointerDown={(e) => {
e.stopPropagation()
onPointerDown?.(e)
}}
onMouseDown={(e) => {
e.stopPropagation()
onMouseDown?.(e)
}}
{...props} {...props}
/> />
) )
@@ -82,9 +90,17 @@ const ToastClose = React.forwardRef<
)} )}
toast-close="" toast-close=""
onClick={(e) => { onClick={(e) => {
e.preventDefault()
e.stopPropagation() e.stopPropagation()
e.nativeEvent.stopImmediatePropagation()
onClick?.(e) onClick?.(e)
}} }}
onPointerDown={(e) => {
e.stopPropagation()
}}
onMouseDown={(e) => {
e.stopPropagation()
}}
{...props} {...props}
> >
<X className="h-4 w-4" /> <X className="h-4 w-4" />