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
Ability to have 3 buttons (Yes, No, Cancel) #1881
Comments
It is currently already possible to encapsulate that ugliness/complexity within a custom enhancer: // define custom enhancer
function withAdvancedButtons (ParentSwal) {
return class extends ParentSwal {
_main (oldParams) {
const {
buttons,
onOpen: superOnOpen = () => {},
...newParams
} = oldParams
newParams.onOpen = popupElement => {
for (const button of buttons) {
// Add custom html and event listeners
}
superOnOpen(element)
}
return super._main(newParams)
}
}
}
// then use it
const MySwal = withAdvancedButtons(Swal)
MySwal.fire({
buttons: [
// ...
]
}) The advantage of this (as opposed to having it built in) is that you can have it (1) today, and (2) with whatever API you desire (without everyone having to collaborate and agree on the perfect one that suits all use-cases). That said.. yes.. I think it would be great to have a perfect API for buttons. |
@zenflow I added your excellent example to the |
No, it's not. It is unusual and, in fact, it's a bad UX. From https://material.io/components/dialogs/#actions
|
I can't come up with a single use-case where the dialog with 3 buttons would be the right way to go. @alexandremix could you please give us the real-life example where 3 buttons would be the requirement? |
@limonte I can imagine up some scenario's where 3 buttons would be desirable:
The comment from material.io about the downside of a third button:
... Does not seem to apply in every situation where there's a third button |
As a user, I would be confused by this dialog if the buttons will be "Yes", "No", and "Cancel" (without the clarification in brackets). The need for long clarifications indicates that something isn't right here and the excessive complexity is presented.
The better (in terms of extendability, maintainability, keyboard accessibility) solution would be the default "OK"/"Cancel" buttons and input type radio or custom input, e.g. PayPal is doing it right: |
@limonte I think there are always different ways to do it, so that more than two buttons aren't necessary, but that it would be nice to leave these UI/UX decisions to the developer. I could continue to argue in favor of having more than two buttons for some situations:
|
I would support the idea of adding a "deny" button, so that we would have "confirm", "deny", & "cancel" buttons, if someone was willing to make the code changes. I would review the PR. I think it would be a fairly straight-forward change, since it would just follow the pattern established with the "confirm" and "cancel" buttons. I.e. we would have new options |
Hi. I agree with @limonte about UX, because dialogs should kept simple. Based in the example, I would put a close icon on top right. Anyway, restricting buttons to their behaviour makes difficult to mantain non-standard dialogs like PayPal's or the following (Which is A more flexible API would be accomplished by allowing an unlimited number of buttons and returning its ID, considering the behaviour only for styling. |
I would reject that idea, because the very next idea would be to add the fourth button with a bunch of API params again (5 params per button). |
@sebaherrera Assuming that what you are agreeing with is the idea that "there should be no more than 2 action buttons". If the dialog needs to get a choice of two options from the user, or else abort/cancel, what would be more simple?
Is there a third option here that I'm not seeing that is simpler than both and uses no more than 2 action buttons? |
@sebaherrera I thought you were advocating that "there should be no more than 2 action buttons"... then what would be the use of this? For the record, I do think that this would be the ideal thing, but it would require revising the API for buttons, which would mean breaking changes (users need to make changes to their code to be able to upgrade to the next version) and would need to be done carefully (no going back once the change is released). I'm not against it, but I think the fast/easy/efficient solution to this issue for now would be to simply extend (not revise) the API as I proposed in #1881 (comment) |
I agree that the next idea (add the fourth button in the same way) would be a bad one, but that doesn't mean that this idea is a bad one (unless you would rather go straight to allowing an unlimited/arbitrary number of buttons). I think this idea is the next best thing to allowing an unlimited number of buttons. because then at least we would be able to get a yes/no (Boolean) response from the user. |
Yes, that'd be preferable. So far we didn't get a lot of user requests for the third button, so the need in that functionality isn't big. Let's take our time and thinking to implement the flexibility of making UI decisions properly instead of copy-pasting APIs which might seem simple at first sight. |
You are wrong here and this is exactly my concern. Inexperienced developers will hurt end-users with modals like this one: Actually, thanks to all participants, I made my mind on this issue. The support for three or more buttons will not be added. That feature will be misused and it'll be in most cases totally unnecessary. The example for three buttons will be added in sweetalert2/sweetalert2.github.io#112 subscribe to that issue to be notified. |
@limonte Since he's been blocked from the sweetalert2 organization for a while now, I think this issue can be unlocked, right? Also I feel the issue should be reopened because, scrolling up, I can clearly see a big lack of effective communication on this issue, due to all people, leading up to your decision (to not support more buttons). A lot of points were missed or not understood or not responded to. It feels like the issue was not given it's "due process". |
@limonte I think the first sub-issue to discuss is this: Observably, many developers have the opinion that having >2 buttons is good and acceptable in some common situations.
Let me know if there's some error in that premise. So shouldn't we, ideally, be allowing them the flexibility to easily design their modals however they want? Don't you think that instead of trying to control the end-user's experience, we should be empowering the developer with that control? I know that we should be helping to guide the developer in developing a nice UX (which is inherently an opinionated kind of thing), but I feel that it isn't (or shouldn't be) our place to intentionally make restrictions/limitations for this purpose. Let's treat users of SweetAlert2 like adults, not children. |
The second sub-issue I see is the actual idea that we should never have <=2 buttons. Hopefully we can agree on the first sub-issue (above) and then this is irrelevant there is no point of discussing it. |
The third sub-issue I can see is actually a separate issue, independent of the whole ">2 buttons supported or not" debate. It is this: To create a model with only 2 action buttons, but neither are Cancel, (e.g. "Yes"/"No", "Confirm"/"Deny", "Donate with PayPal"/"Donate with Debit or Credit card"), we currently need to misuse the Cancel button, such that clicking "No" causes a dismissal and we handle that particular type of dismissal (i.e. dismissal via Cancel button) differently because it is not actually a dismissal. It's the simple "problem" of a nice API that you can work with cleanly. The improvement could be something like: const {dismiss, value} = await YesNoSwal.fire('Would you like to save your changes?')
if (dismiss && dismiss !== Swal.DismissReason.cancel) {
return
}
const saveChanges = dismiss !== Swal.DismissReason.cancel
// or saveChanges could equally be defined as follows:
const saveChanges = Boolean(value)
closeCurrentDocument({saveChanges}) to: const {dismiss, value: saveChanges} = await YesNoSwal.fire('Would you like to save your changes?')
if (dismiss) {
return
}
closeCurrentDocument({saveChanges}) I'd rather look at the first two sub-issues first, but @limonte I'm curious if this is something you would want to solve. |
I didn't change my mind, still against adding the complexity and bringing breaking changes to our users for the sake of 1% cases (I'm judging by the number of requests for this functionality). And from those 1% cases, at least half will be misused.
I believe that we should treat people on an individual basis, some of the users deserve our attention, some need guidance and advice on good UI practices. I will reopen this issue for one purpose: to gather requests for this feature from the community. Please discontinue the discussion, we can continue it once there's a need for this feature.Please add 👍 to the issue, if you need 3 or more buttons for your projectAlso, it'd be useful for us if along with 👍 you can describe your use-case where 3 or more buttons are needed. |
In my case the API returns a list of actions to be performed depending on the status of the response. It might return just a success message, an error, or the list of actions that could be performed. For that I'd like to display a dropdown button with the actions. I actually don't need the third button, per se, I need to ability to have a dropdown, but I think it comes down to this customization in the end. I'd have something like this: |
Thank you for your input @eestein, but your requirements are different and unrelated to this particular feature-request. |
Thinking out-of-the-box:
|
Hello! I agree with @zenflow for this part :
I think it's up to the developer to choose his UX and not the module he uses. Especially that a developer will succeed in one way or another, but not necessarily in the right way without an official way offered by this module. To present my case, I am developing a web application allowing a client to manage reservations from a tablet (important point). Not having much space on its screen, I cannot propose a column in my table with two distinct actions which are "cancel the reservation" and "confirm the reservation". So, to keep it simple, I have to offer a popup allowing my client, when he clicks on a reservation, to: do nothing, cancel the reservation and confirm the reservation. Here is the result (in French sorry): So, even if it remains possible without an official way, I think SweetAlert should offer, in one way or another, the possibility of adding custom buttons with associated event listeners. However, I completely agree with you @limonte on this point:
This change should not bring breakings changes to the current behavior, but should be an option, it remains to be seen how to implement this. Thanks a lot to each contributors of this library, I've been using it for a while now. Have a good day and take care! |
In an Admin-Panel if you have the Option to perform a Action which "can" send a E-Mail to a Customer or simply perform the Action without sending a E-Mail you would need either 2 Action-Buttons:
It's a much cleaner UI/UX to have ONE Action Button "DO Action" and then Ask with a SWAL for the desired outcome: Imo a "deny"-Button as discussed would make sense for that reason. |
My use case: In my application, the users can import financial data from a file. "Do you want to delete existing data before the import?" Both options perform the import and execute database changes. For several reasons users might decide that they do not want to import at all and would prefer to abort - which they currently cannot do. Therefore it is a feature request by our users (!) to add a third button: Button 3: Cancel Whether or not multiple buttons are confusing to the user always depends on the context. Really, coming from C#, I had expected this feature request to be solved in a matter of 5 minutes or so. |
i think we're putting too much emphasis on the "third button" for the sake of a "third button", which, as limonte said, would add a whole sort of new API params. But i understand that that itself could bring a whole lot of problems like "what if i want to put custom buttons inbetween the two standard ones?" But anyways putting my 2 cents on a use case for custom buttons (as i really don't like to call it "third button") But this is an edge case even inside my own project so I reconsidered the viability of using swal's API for that task. though The necessity of three buttons is not really a 1% case in that context, and it absolutely shouldn't be dismissed altogether just because material said so for its mostly mobile/web context |
Thank you all for your feedback and opinions, they are much appreciated ❤️ I will implement @zenflow's suggestion for the upcoming v10 release:
v10 will be released next week. Stay tuned 📻 #2043 PS.
@PlanetSensei in JS we're more careful with adding new features, because every single one should and will be maintained in the future. |
Everyone who's interested in reviewing the upcoming "deny" button is welcome: #2044 |
This has finally been implemented in v10 🎉 Live demo: https://sweetalert2.github.io/#three-buttons |
Another demo which shows how to reorder buttons and add a gap between them: https://sweetalert2.github.io/recipe-gallery/three-buttons-dialog.html |
Its usual to have 3 options in everything, i think 2 options in swal is too short, 3 options would be just perfect. As it fits almost all cases.
Even in VB there's a yesnocancel option.
If this is already a functionality I don't seem to find any documentation in the official website, or in here.
I found some examples but they are for sweetalert1 not this version.
I arrived here and tried to search in here as well. I don't seem to find it.
I feel like making custom html and adding event listeners in all buttons seems to ugly.
Can someone guide me to this functionality? Or at least consider implementing it?
The text was updated successfully, but these errors were encountered: