Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading onAutoClose not working #514

Open
molvqingtai opened this issue Nov 8, 2024 · 1 comment
Open

Loading onAutoClose not working #514

molvqingtai opened this issue Nov 8, 2024 · 1 comment

Comments

@molvqingtai
Copy link
Contributor

toast.loading('hello,world', {
  duration:1000,
  onAutoClose: ({ id }) => toast.dismiss(id) // Not called
})

When timed out, onAutoClose is not called

Related issues: #476

@ynng3
Copy link

ynng3 commented Nov 11, 2024

The reason a toast of type loading does not close is due to the condition set in the code. Specifically, in the Toast component, there are checks to prevent the automatic closing of a loading toast.

// https://github.com/emilkowalski/sonner/blob/main/src/index.tsx#L175
if ((toast.promise && toastType === 'loading') || toast.duration === Infinity || toast.type === 'loading') return;

This logic ensures that if the toast has a loading type, it will not proceed with the auto-close functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants