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

Chaining modals and running modals in sequence has incorrect behaviour #2730

Closed
daattali opened this issue May 15, 2024 · 3 comments
Closed

Comments

@daattali
Copy link

Current behavior

These are a few interrelated bugs. I'll show three examples

  1. When calling two modals one after another: only the second one shows.
  2. When calling two modals, with the first one calling another modal in its promise: the modal in the promise gets shown immediately
  3. When calling two modals, with each of them having another modal in its promise: the modal in the second one's promise gets shown

Expected behavior

I would expect to see the modals in the correct order. In the three cases described above:

  1. Show the first modal, and only after it gets dismissed, show the second
  2. Either show the first modal, then the one in its promise, and then the second one. Or the first one, then the second, then the one in the promise. It's up for debate what is the more correct behaviour, but the current behaviour is definitely incorrect
  3. Similar logic to 2

Live demo !!! THIS FIELD IS REQUIRED !!!

All three code samples are in this pen: https://codepen.io/daattali/pen/mdYebqx

@limonte
Copy link
Member

limonte commented May 17, 2024

@limonte limonte closed this as completed May 17, 2024
@daattali
Copy link
Author

Using progress steps is a related feature that can achieve a similar result, but it's inherently a very different (and much more complex) syntax for a different usecase. There are cases when multiple popups might need to happen, in an unrelated manner where the different popups don't know about each other.

Example 1: imagine if the user clicks button A, then popup A is shown. If they click button B, popup B is shown. If they click button C, both popups are shown. It would lead to much cleaner and more intuitive code if C can simply call both A and B, rather than having to use completely different code.

Example 2: imagine that popup A happens on a schedule, and popup B is currently showing because of a user action. When A is triggered, it'll automatically take over B.

My reason for wanting this to be simpler is because I have a package in a different language (R) that brings sweetalert's functionality, and currently users can call shinyalert("one"); shinyalert("two") to see two successive popups. I care a lot about ease of use, and I believe that requiring end users to learn a completely different syntax and write a lot more code for doing something trivial is not the correct behaviour. The API should be as simple and clean to use, and the current way is great if you truly have "steps", but not for chaining modals.

@limonte
Copy link
Member

limonte commented May 17, 2024

async/await is the answer.

@sweetalert2 sweetalert2 locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants