From 8a8fad1fae4c8977793c1b77e6f2f807d16f796e Mon Sep 17 00:00:00 2001 From: Hunter Martin Date: Thu, 7 Nov 2024 16:59:21 -0800 Subject: [PATCH] Fix top position swipe direction (#513) --- src/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index fca6d4f..a3ea512 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -320,15 +320,15 @@ const Toast = (props: ToastProps) => { const yPosition = event.clientY - pointerStartRef.current.y; const isHighlighted = window.getSelection()?.toString().length > 0; - const swipeAmount = Number(toastRef.current?.style.getPropertyValue('--swipe-amount').replace('px', '') || 0); + const swipeAmount = y === 'top' ? Math.min(0, yPosition) : Math.max(0, yPosition); - if (swipeAmount > 0) { + if (Math.abs(swipeAmount) > 0) { setIsSwiped(true); } if (isHighlighted) return; - toastRef.current?.style.setProperty('--swipe-amount', `${Math.max(0, yPosition)}px`); + toastRef.current?.style.setProperty('--swipe-amount', `${swipeAmount}px`); }} > {closeButton && !toast.jsx ? (