diff --git a/packages/ui-react/lib/Toast/showToast.tsx b/packages/ui-react/lib/Toast/showToast.tsx index db847b9..a8b0667 100644 --- a/packages/ui-react/lib/Toast/showToast.tsx +++ b/packages/ui-react/lib/Toast/showToast.tsx @@ -46,6 +46,7 @@ const moreTimeClose = (div: HTMLDivElement) => { if (toastContainer?.contains(div)) { toastContainer?.removeChild(div); toasts = toasts.filter((toast) => toast !== div); + checkToastContainer(); // Check if toasts are empty } }, 400); }, 5000); @@ -55,9 +56,10 @@ const moreThreeClose = () => { if (toasts.length > 3) { toasts.shift(); setTimeout(() => { - while (toastContainer && toastContainer?.childNodes.length > 3 && toastContainer.firstChild) { + while (toastContainer && toastContainer.childNodes.length > 3 && toastContainer.firstChild) { toastContainer.removeChild(toastContainer.firstChild); } + checkToastContainer(); // Check if toasts are empty }, 300); } }; @@ -65,6 +67,7 @@ const moreThreeClose = () => { const closeToast = (div: HTMLDivElement) => { setTimeout(() => { div.remove(); + checkToastContainer(); // Check if toasts are empty }, 300); toasts = toasts.filter((toast) => toast !== div); addListener(div); @@ -103,3 +106,10 @@ const addListener = (div: HTMLDivElement) => { div.addEventListener('mouseenter', handleMouseEnter); div.addEventListener('mouseleave', handleMouseLeave); }; + +const checkToastContainer = () => { + if (toasts.length === 0 && toastContainer) { + document.body.removeChild(toastContainer); + toastContainer = null; // Reset toastContainer + } +}; diff --git a/packages/ui-react/package.json b/packages/ui-react/package.json index 8521cce..27bbb55 100644 --- a/packages/ui-react/package.json +++ b/packages/ui-react/package.json @@ -1,6 +1,6 @@ { "name": "@ui-aurora/react", - "version": "0.0.29", + "version": "0.0.30", "description": "A React UI library built for SASTOJ", "author": "sast", "license": "MIT",