312 points · by thefox · 12y ago · 106 comments
If something is that important then you'll usually want to give the user a choice from a set of options - e.g. if the user is doing something that can destroy data without the possibility of undoing their actions then you'll want a dialogue that asks them if they're sure. That should block all other interaction because it really is important. When the user has no input though, and there's nothing they can do but click 'ok', there's no need to use an alert. Just put a message on the screen that's high enough up the page's information hierarchy that they've very likely to see it. Make it sticky (so it's there until the user dismisses it, but doesn't block other actions) if it's something that they need to confirm that they've seen.
Don't force the user to do things your way. Guide the user, sure, but let them do things their way.
So alerts are pretty much a must for us, and the obnoxious interruptions help us make the regulators happy. Getting a nicer alert like this will make our customers a bit happier while still keeping us in compliance.
But our use case is of course not standard. Usually alerts are like Satan.
> if the user is doing something that can destroy data without the possibility of undoing their actions then you'll want a dialogue that asks them if they're sure
if(confirm(....)) { doStuff() } else { cleanup() }
This should at least have a callbacks for the different buttons.In terms of design, I don't like absolute vertical centering. It should be higher on the page. I use 1:2, or 1:1.6 for the top/bottom margin as my "default" modal centering.
http://tristanedwards.me/sweetalert
Unfortunately, there's only one function so this isn't useful if you want to run code when the user cancels the dialog:
https://github.com/t4t5/sweetalert/blob/750a0fd72c3beaa6d4d7...
So, if I click OK am I acknowledging the alert to dismiss it or is performing an action? If I hit cancel am I canceling the alert or canceling the action?
Its still terrible UI. Limiting the options to things like "ok" and "cancel" can be very confusing to the end user.
Don't you agree? {OK} {Cancel}
Are you sure you want to delete? {Yes, delete thing X} {No, keep it}
Would you still find that insufficient communication with the user? No sarcasm, genuinely interested to get your opinion.
sweetAlert('hello')With that said, I think it looks great
1. It's less than 5KB.
2. It overrides the existing alert function.
3. It extends the existing alert function.
What I don't like about Sweet Alert:
1. It's bloated for what it does... > 30KB
2. The short-hand swal doesn't make sense or read well.
Now this isn't a great use but its one maybe acceptable use if my browser really didn't work on their site.
Confirm dialogs particularly around destructive actions are decent use cases for UI blocking.
We'll be nice and give the author the benefit of the doubt and say it's juxtaposition :P
- Unexpected behavior on mobile devices. (since they usually implement their own alerts)
Just make it backwards-compatible and it will be pretty sweet. Until then it's not serious.
https://github.com/t4t5/sweetalert/commit/2413e5cbcd1fe3d6e1...
- Heavy use of Javascript for what CSS is designed for: https://github.com/t4t5/sweetalert/blob/master/lib/sweet-ale...
- Inconsistent between function spacing followed by mixed tabs and spaces
- Odd use of DOM based attributes to pass configuration options
- Colourspace manipulation on each call where SASS would be effective https://github.com/t4t5/sweetalert/blob/master/lib/sweet-ale...
- Includes jquery, but uses it very little, instead opting to re-invent the wheel in most cases.
- Strange click event firing, gratuitous use of magic key code numbers https://github.com/t4t5/sweetalert/blob/master/lib/sweet-ale...
etc...
(As you can probably tell, I do not like this style at all)
If so, there's a slight typo on the "See it in action!" page (http://tristanedwards.me/sweetalert). For the "A warning message, with a function attached to the "Confirm"-button" demo, the code displayed says 'alert("Booyah!");' but the alert being displayed says 'Deleted!'
I recommend using the content in the link itself: it's described as 'awesome' not 'beautiful'.
What's funny is that since this doesn't actually work like a JS Alert, it's actually quite 'ugly'. ;)
Hopefully very few JS developers are using alerts in their production code (or dev for that matter!), and if they are they're probably not interested enough in user-friendly design to seek out this replacement.
I notice that even large apps like gmail and google calendar use native alerts (and I've been using them a bit more under certain circumstances—something has gone terribly wrong). What about native alerts in all situations equals unfriendly design—esp. when trying to mimic mobile native apps, but needing to span the gap from OS to OS?
I actually think SweetAlerts looks pretty nice for those kind of in-app notifications, which was the point I was trying to make. (Though seeing comments from people who have dug in further it seems like it has some issues)
The only issue I see with doing it that way is if you are in another Window and click to get focus, but you should deal with the alert when it appears since it is a part of completing a task.
Usually people only switch windows when they have completed a task.
Click the Confirm example: Click "cancel" to clear the dialogue.
Click the button again: Click "delete me" and you don't get the deleted alert that you normally get.
Also, I suggest optionally only blocking a portion of the DOM and centering over it. This would allow a component to lock without locking the application.
Finished your sentence for you.
But needs more callback functions...
Chrome supports the <dialog> element which is guaranteed to appear on top of whatever page its injected on.
Javsacript's Alert, prompt, also guarantee it will appear on top.