Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix: prevent Radix Dialog and Vaul Drawer dismissal when closing a toast

unrenamed0c84091fbbd5
diff --git a/packages/ui/src/input-select.tsx b/packages/ui/src/input-select.tsx
index cca4d5670b..299e55d40e 100644
--- a/packages/ui/src/input-select.tsx
+++ b/packages/ui/src/input-select.tsx
@@ -197,7 +197,18 @@ export function InputSelect({
</Drawer.Trigger>
<Drawer.Overlay className="fixed inset-0 z-40 bg-gray-100 bg-opacity-10 backdrop-blur" />
<Drawer.Portal>
- <Drawer.Content className="fixed bottom-0 left-0 right-0 z-50 mt-24 rounded-t-lg border-t border-gray-200 bg-white">
+ <Drawer.Content
+ className="fixed bottom-0 left-0 right-0 z-50 mt-24 rounded-t-lg border-t border-gray-200 bg-white"
+ onPointerDownOutside={(e) => {
+ // Prevent dismissal when clicking inside a toast
+ if (
+ e.target instanceof Element &&
+ e.target.closest("[data-sonner-toast]")
+ ) {
+ e.preventDefault();
+ }
+ }}
+ >
<Command
ref={commandRef}
className="relative"
diff --git a/packages/ui/src/modal.tsx b/packages/ui/src/modal.tsx
index f4869fa8c9..6946bd0202 100644
--- a/packages/ui/src/modal.tsx
+++ b/packages/ui/src/modal.tsx
@@ -60,6 +60,15 @@ export function Modal({
<Drawer.Portal>
<Drawer.Overlay className="fixed inset-0 z-50 bg-gray-100 bg-opacity-10 backdrop-blur" />
<Drawer.Content
+ onPointerDownOutside={(e) => {
+ // Prevent dismissal when clicking inside a toast
+ if (
+ e.target instanceof Element &&
+ e.target.closest("[data-sonner-toast]")
+ ) {
+ e.preventDefault();
+ }
+ }}
className={cn(
"fixed bottom-0 left-0 right-0 z-50 flex flex-col",
"rounded-t-[10px] border-t border-gray-200 bg-white",
@@ -99,6 +108,15 @@ export function Modal({
<Dialog.Content
onOpenAutoFocus={(e) => e.preventDefault()}
onCloseAutoFocus={(e) => e.preventDefault()}
+ onPointerDownOutside={(e) => {
+ // Prevent dismissal when clicking inside a toast
+ if (
+ e.target instanceof Element &&
+ e.target.closest("[data-sonner-toast]")
+ ) {
+ e.preventDefault();
+ }
+ }}
className={cn(
"fixed inset-0 z-40 m-auto h-fit w-full max-w-md",
"border border-gray-200 bg-white p-0 shadow-xl sm:rounded-2xl",
diff --git a/packages/ui/src/popover.tsx b/packages/ui/src/popover.tsx
index 03a75816c7..93ce95e27e 100644
--- a/packages/ui/src/popover.tsx
+++ b/packages/ui/src/popover.tsx
@@ -47,6 +47,15 @@ export function Popover({
<Drawer.Content
className="fixed bottom-0 left-0 right-0 z-50 mt-24 rounded-t-[10px] border-t border-gray-200 bg-white"
onEscapeKeyDown={onEscapeKeyDown}
+ onPointerDownOutside={(e) => {
+ // Prevent dismissal when clicking inside a toast
+ if (
+ e.target instanceof Element &&
+ e.target.closest("[data-sonner-toast]")
+ ) {
+ e.preventDefault();
+ }
+ }}
>
<div className="sticky top-0 z-20 flex w-full items-center justify-center rounded-t-[10px] bg-inherit">
<div className="my-3 h-1 w-12 rounded-full bg-gray-300" />