fix: cannot close notification manually (#11490)

This commit is contained in:
Hash Brown 2024-12-09 17:55:06 +08:00 committed by GitHub
parent 00ac7edeb3
commit 2866383228
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)
}
}