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

Make it possible to replace a toast whilst keeping its position in the stack #102

Open
MathiasWP opened this issue May 6, 2024 · 2 comments

Comments

@MathiasWP
Copy link

Describe the feature

It would be nice if it was possible to replace a toast with a different one, similar to how toast.promise replaces the loading toast with a success or error toast.

Having this functionality would make it helpful to implement a more sophisticated stack of toasts, eg if you want to show a loader toast and then separate error/success/info toasts based on the outcome.

For example, we have multiple locations where an operation consists of making multiple calls to a server, but for the user it behaves as one transaction, so we want to show only one loading toast and then separate error messages based on where the operation failed.

@MathiasWP MathiasWP changed the title Make it possible to replace a toast Make it possible to replace a toast whilst keeping its position in the stack May 6, 2024
@jaycdev
Copy link

jaycdev commented May 29, 2024

Isn't this possible by updating the toastId of that toast?

<script>
	async function onClick() {
		const toastId = Math.random();
		toast.loading(`Loading with ${toastId}`, {id: toastId});
		await new Promise(resolve => setTimeout(resolve, 4000));
		toast.warning(`Warning with ${toastId}`, {id: toastId});
		await new Promise(resolve => setTimeout(resolve, 4000));
		toast.error(`Error with ${toastId}`, {id: toastId});
	}
</script>

<Button on:click={onClick}>Click me!</Button>

Click the button several times with delays and you'll see the toasts change to loading, warning and error with their respective id/text, while staying in the same position

@CNSeniorious000
Copy link

But this way it won't have the transition animation like toast.promise

#109

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

3 participants