Skip to content

Commit dda0af3

Browse files
committed
fix: mount toaster to portalRoot to show on top of modals
1 parent a542a26 commit dda0af3

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

bun.lockb

32 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@radix-ui/react-dropdown-menu": "^2.1.2",
3737
"@radix-ui/react-icons": "1.3.0",
3838
"@radix-ui/react-popover": "^1.0.7",
39+
"@radix-ui/react-portal": "^1.1.2",
3940
"@radix-ui/react-scroll-area": "^1.0.3",
4041
"@radix-ui/react-select": "^2.0.0",
4142
"@radix-ui/react-slot": "^1.0.2",

src/components/ui/toaster.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { Portal } from "@radix-ui/react-portal"
2+
3+
import { portalRoot } from "@/lib/portal-root"
14
import {
25
Toast,
36
ToastClose,
@@ -12,18 +15,20 @@ export function Toaster() {
1215
const { toasts } = useToast()
1316

1417
return (
15-
<ToastProvider>
16-
{toasts.map(({ id, title, description, action, ...props }) => (
17-
<Toast key={id} {...props}>
18-
<div className="grid gap-1">
19-
{title && <ToastTitle>{title}</ToastTitle>}
20-
{description && <ToastDescription>{description}</ToastDescription>}
21-
</div>
22-
{action}
23-
<ToastClose />
24-
</Toast>
25-
))}
26-
<ToastViewport />
27-
</ToastProvider>
18+
<Portal container={portalRoot}>
19+
<ToastProvider>
20+
{toasts.map(({ id, title, description, action, ...props }) => (
21+
<Toast key={id} {...props}>
22+
<div className="grid gap-1">
23+
{title && <ToastTitle>{title}</ToastTitle>}
24+
{description && <ToastDescription>{description}</ToastDescription>}
25+
</div>
26+
{action}
27+
<ToastClose />
28+
</Toast>
29+
))}
30+
<ToastViewport />
31+
</ToastProvider>
32+
</Portal>
2833
)
2934
}

0 commit comments

Comments
 (0)