浏览代码

fix: cannot close notification manually (#11490)

Hash Brown 4 月之前
父节点
当前提交
2866383228
共有 1 个文件被更改,包括 16 次插入2 次删除
  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)
   }
 }