Bladeren bron

fix: cannot close notification manually (#11490)

Hash Brown 4 maanden geleden
bovenliggende
commit
2866383228
1 gewijzigde bestanden met toevoegingen van 16 en 2 verwijderingen
  1. 16 2
      web/app/components/base/toast/index.tsx

+ 16 - 2
web/app/components/base/toast/index.tsx

@@ -123,11 +123,25 @@ Toast.notify = ({
     const holder = document.createElement('div')
     const root = createRoot(holder)
 
-    root.render(<Toast type={type} size={size} message={message} duration={duration} className={className} />)
+    root.render(
+      <ToastContext.Provider value={{
+        notify: () => {},
+        close: () => {
+          if (holder) {
+            root.unmount()
+            holder.remove()
+          }
+        },
+      }}>
+        <Toast type={type} size={size} message={message} duration={duration} className={className} />
+      </ToastContext.Provider>,
+    )
     document.body.appendChild(holder)
     setTimeout(() => {
-      if (holder)
+      if (holder) {
+        root.unmount()
         holder.remove()
+      }
     }, duration || defaultDuring)
   }
 }