Skip to content

An opinionated toast component for React.

Fix layout shift (#61)

Emil Kowalski12348939bb0c
diff --git a/package.json b/package.json
index 0b4421a..678eec3 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "sonner",
- "version": "0.3.0",
+ "version": "0.3.1",
"description": "An opinionated toast component for React.",
"main": "dist/index.js",
"module": "dist/index.mjs",
diff --git a/src/index.tsx b/src/index.tsx
index 718cd04..333a8a7 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -454,6 +454,8 @@ const Toaster = (props: ToasterProps) => {
return () => document.removeEventListener('keydown', handleKeyDown);
}, [hotkey]);
+ if (!toasts.length) return null;
+
return (
// Remove item from normal navigation flow, only available via hotkey
<section aria-label={`Notifications ${hotkeyLabel}`} tabIndex={-1}>
diff --git a/test/src/app/page.tsx b/test/src/app/page.tsx
index 3a65a19..831c010 100644
--- a/test/src/app/page.tsx
+++ b/test/src/app/page.tsx
@@ -11,7 +11,6 @@ export default function Home() {
return (
<>
- <h1>tests</h1>
<button data-testid="default-button" className="button" onClick={() => toast('My Toast')}>
Render Toast
</button>
diff --git a/website/app/page.tsx b/website/app/page.tsx
index fc3c066..1fbfe23 100644
--- a/website/app/page.tsx
+++ b/website/app/page.tsx
@@ -20,6 +20,7 @@ export default function Home() {
return (
<>
+ <Toaster richColors={richColors} closeButton={closeButton} expand={expand} position={position} />
<main className="container">
<Hero />
<div className="content">
@@ -32,7 +33,6 @@ export default function Home() {
</div>
</main>
<Footer />
- <Toaster richColors={richColors} closeButton={closeButton} expand={expand} position={position} />
</>
);
}