r/javascript • u/limonmonte • Feb 12 '18
SweetAlert2 - a beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes (alert, prompt, toast, etc.)
https://sweetalert2.github.io/14
u/davidnknight Feb 12 '18
Looks great, although on a quick test on mobile (iPhone) the modal with long text doesn’t scroll very fluidly, takes ages to scroll. Are you aware of this?
Also, content changes behind the modal when opening a modal but returns to its original state when closing, and its really obvious, also looks and feels weird. Again, known issue?
17
u/limonmonte Feb 12 '18
Looks great, although on a quick test on mobile (iPhone) the modal with long text doesn’t scroll very fluidly, takes ages to scroll. Are you aware of this?
Now yes, thanks for reporting: https://github.com/sweetalert2/sweetalert2/issues/905
Also, content changes behind the modal when opening a modal but returns to its original state when closing, and its really obvious, also looks and feels weird. Again, known issue?
Nope, and I can't reproduce this. Could you please record that and submit the issue: https://github.com/sweetalert2/sweetalert2/issues
Many thanks @davidknight for mentioning these issues, we'll work on the iOS user experience.
2
Feb 13 '18
I see the same issue. Using the web view inside Apollo. Tried in Safari too, and it’s the same.
1
u/limonmonte Feb 15 '18
I see the same issue. Using the web view inside Apollo. Tried in Safari too, and it’s the same.
The same to first one or the same to second one? :)
2
Feb 15 '18
Slow scrolling in both.
2
u/limonmonte Feb 15 '18
Slow scrolling should be fixed in the latest version, could you please confirm that: https://sweetalert2.github.io/
3
15
u/johnyma22 Feb 12 '18
This is how communities should work. Props to both for appropriate positively focused behavior.
2
u/lamb_pudding Feb 13 '18
The second issue could have to do with overflow changing thus removing and showing the scroll bar on <body>. Totally just making a guess though since on mobile.
2
u/limonmonte Feb 15 '18
the modal with long text doesn’t scroll very fluidly, takes ages to scroll.
This issue is fixed in the latest release.
Also, content changes behind the modal when opening a modal but returns to its original state when closing, and its really obvious, also looks and feels weird. Again, known issue?
I'm still not able to reproduce this, but it's reported: https://github.com/sweetalert2/sweetalert2/issues/918
2
u/limonmonte Feb 15 '18
Also, content changes behind the modal when opening a modal but returns to its original state when closing, and its really obvious, also looks and feels weird. Again, known issue?
Fixed in the latest release! Thanks again!
8
u/limonmonte Feb 12 '18 edited Feb 12 '18
A beautiful SweetAlert2 + Angular integration: https://github.com/sweetalert2/ngx-sweetalert2
2
u/saroff Feb 12 '18
How can i call
.showLoading()using angular integration? Or any other method from native sweet alert.4
u/toverux Feb 12 '18
SweetAlert2 has type declarations, is module-bundlers friendly, and therefore can be directly imported with an
importstatement (import swal from 'sweetalert2'). Then, use the native Swal2 functions.You can also get an instance of a <swal> component (
@ViewChild('swal') public swal: SwalComponent;) and then use thethis.swal.nativeSwalshorthand to access the original Swal2 API (reminder: it's static, there is NOT one instance per modal).
10
u/cuddleshame Feb 12 '18
upvoting for accessibility, great job
11
u/limonmonte Feb 12 '18
A11y is a must in 2018.
-10
u/cuddleshame Feb 12 '18
careful, the webdev subs are lousy with hacks who'll scream at you over this claim
3
u/the_argus Feb 12 '18
Dynamic queue example doesn't work
Unhandled promise rejection
6
u/limonmonte Feb 12 '18
fixed in https://github.com/sweetalert2/sweetalert2.github.io/commit/75087f4f75cca441a6f3758251587ccc2da3ed67 thanks for reporting!
3
u/build_n_break Feb 12 '18
How does it differ from SweetAlert (https://sweetalert.js.org/)? Did you fork it? Why?
7
u/DOG-ZILLA Feb 12 '18
I think it was forked a long time ago. The original was abandoned I believe.
8
u/limonmonte Feb 12 '18
The original plugin was unmaintained for a long time, than a short period of maintainace and now it's unmaintained again. External PRs and issues are ignored.
Compare http://isitmaintained.com/project/t4t5/sweetalert and http://isitmaintained.com/project/sweetalert2/sweetalert2
I forked it 3 years ago and now SweetAlert2 is more popular (downloads per month) than SweetAlert. Here's the migration guide from the original one: https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2
2
0
Feb 12 '18
[deleted]
4
u/limonmonte Feb 12 '18
Should work just fine, here's the Bootstrap 4 + SweetAlert2 example: https://jsfiddle.net/limon/hz6un8s0/
2
u/drowsap Feb 12 '18
The spring animation is a little sharp, I'd put some more damping on it.
1
u/limonmonte Feb 12 '18
We are trying to make this project as much community-driven as possible, the contributing steps are very easy: https://github.com/sweetalert2/sweetalert2#contributing
I would be more than happy to review and merge your PR, thanks in advance!
2
u/manafount Feb 12 '18 edited Feb 12 '18
I like it!
However, I am getting a slightly jarring content change when the modal opens/closes, as mentioned by /u/davdnknight
From what I can tell, it's caused by the modal getting rid of the side scrollbar (and changing the width of the page in the process), then having the scrollbar reappear on close (and going back to its original width). This makes the content "jump" a few pixels left then right.
Here's a gif.
1
u/limonmonte Feb 13 '18
Thanks for the nice issue-report! Could you please specify OS and browser you were using to record this gif?
2
2
u/psyanara Feb 16 '18
Is the background nyan cat supposed to be behind the modal itself?
iOS 9.3 (Safari and Chrome)
1
u/limonmonte Feb 16 '18
Yes, it's a background :)
2
u/psyanara Feb 17 '18
Just checking. I thought perhaps the cat would be in the modals background rather than the windows.
We're still using the original sweetalert. I'll have to take a look this weekend and see if we can seamlessly switch to y'alls product.
1
u/limonmonte Feb 17 '18
You can have nyan cat as a modal background: https://jsfiddle.net/ad3quksn/482/
But I'm just not sure if that's a good UX :)
Here's the migration guide which should help you to switch from the original sweetalert: https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2
13
17
u/Tinpotray Feb 12 '18
“Zero dependencies”.
Is there a better phrase in JS world than this???
Thank you op. 😊
4
u/scunliffe Feb 12 '18
This depends on Promises doesn't it? If so, the dependency on Promises means no IE support: https://caniuse.com/#search=promise and as such you can't use it as a script execution blocker until you have a result like the native confirm(). (not saying that's a bad thing, just that its a thing to be aware of)
19
u/toverux Feb 12 '18
Promise is still a normalized, living standard. Polyfills cannot be considered as "normal" dependencies. SweetAlert uses standards, nothing more, nothing less.
6
u/Tinpotray Feb 12 '18
Good point but to be honest I’ve long stopped worrying about IE support - partly because it’s excruciating but mostly because I make Cordova apps these days. 😊
3
u/scunliffe Feb 12 '18
Lets just say I’m jealous... of that scenario :-(
5
u/Tinpotray Feb 12 '18
Hate to rub it in... but just explored the GitHub repo and found this:
https://github.com/sweetalert2/ngx-sweetalert2
Angular support...! THAK YOU AGAIN OP!!! :D
2
1
u/m0okz Feb 13 '18
Surely you don't enjoy using Cordova....
1
u/Tinpotray Feb 13 '18
Well I build Cordova apps... mostly using ionic and angular.
The most I actually do with Cordova is run a few cli installs and run build.
Other than that I don’t have an opinion honestly.
1
u/skylarmt Feb 13 '18
Look at Mr. Fancy Code over here using Ionic. Us common folk use Bootstrap and custom media queries to build our UI.
6
1
u/Zardoz84 Feb 12 '18
Don't uses <dialog>
1
u/limonmonte Feb 21 '18
<dialog> is really new and is not widely supported yet: https://caniuse.com/#feat=dialog so it would require another polyfill, but not only on IE this time. In the meantime, role='dialog" is a well-known ARIA attribute that works very well. So, one day probably, but it seems premature now.
1
u/Zardoz84 Feb 21 '18
I have a responsive dialog using <dialog> + polyfill and it works very nice on IE 10, FF, Edge, Chrome, Android ...
6
3
1
u/jmperro Feb 12 '18
This is awesome!! I'll use it in all my future projects!
2
u/limonmonte Feb 12 '18 edited Feb 12 '18
You will not regret this :) We are extremely good in hearing out the community: https://isitmaintained.com/project/sweetalert2/sweetalert2
2
2
2
2
2
2
u/Gaelican Feb 12 '18
I've been using this for years. I use it instead of a bootstrap modal whenever I can.
I believe the main reason for when I can't use it is when I need to have more than 1 input in the pop-up. And I don't think I remember it having a good way to customize the HTML content.
In version 1, I modified it to allow for more than 2 buttons and that's now a feature in version 2.
2
u/nwsm Feb 12 '18 edited Feb 12 '18
Looks really nice. I recently made basically the same thing for a Vue project building on bootstrap-vue's modal to be able to change the modal content and buttons and 0-inf inputs.
By the end it got pretty custom, to the point I feel I should make it from scratch, without bootstrap-vue. I might look into this later :)
Can you cancel the popup animation when chaining? The modal chaining looks like it would be fine for supporting multiple inputs, except for that annoying popup animation every time.
2
u/forcefx Feb 12 '18
Wow! Love these and have used them for awhile. Great job and great looking modals 😁
2
2
2
2
u/zvive Feb 13 '18
Discovered this gem a few months ago, absolutely love it, using the Vue wrapped version in most of my projects.
2
2
2
u/Cha0sCat Feb 13 '18
This is awesome. Didn't know I need it but I do. Am so gonna use this in my future projects. Thank you!
2
u/thingmabobby Feb 13 '18
I’ve been looking to replace the default alerts on a project I’ve been working on and this definitely fits the bill! It looks and feels great - smooth and professional. Thanks!
2
u/RottiBnT Feb 17 '18
This is great. Every project should use this as a documentation standard. Example - code snippet. And so a many examples. Love it.
2
2
Feb 12 '18
Very nice and professional looking. My only concern with using something like this is the HUGE footprint - minified and gzipped it's 13KB - to put that into comparison, it's almost half the size of jQuery 3 (which is 30KB minified + gzipped).
I'd imagine that's just because of the shear amount of flexibility and options you get but meh, seems pretty hefty for a confirmation box.
Would be nice to have a more "modular" design so you can import the bare basics and styles you need.
3
u/toverux Feb 12 '18 edited Feb 12 '18
Yes! We're totally aware of that and this is due to a big number of features, some of which being decouplable or not, given the current state of things. We recently added bundlesize to watch the final bundle size and we'll be more careful on future additions. Also, we're thinking about important rewrites in the future to allow a more modular system and benefit from tree-shaking in module bundlers, for example. For now, we have some architectural technical debt that is coming from the original project. As time passed, features have been added, while the older architecture/API was kept to ease migration and compatibility.
In the end, 13 KB is a lot or is tolerable depending on what you're doing. If you're working on a big backend with a lot of UI libraries that already weighs more than 500 KB and make intensive usage of modals, then it's nothing. If you want a super fast website with a single alert, it's just big.
But to conclude, don't worry, we're on it. Just don't expect it tomorrow as we're in a stabilization phase and future APIs are not defined yet as there are many ideas but no concrete proposals.
1
1
u/Arkaad Feb 13 '18
Since I'm already using Bootstrap, I was using Bootstrap Dialog which means that JQuery was also needed.
SweetAlert2 might be a better solution!
0
Feb 12 '18
But please customize it. Shady AD sites are all using this alert style.
3
u/limonmonte Feb 12 '18
Those aren't shady AD sites, that's Carbon Ads which aren't included in the library, but in the presentation website. Carbon Ads is highly relevand technical ads, a lot of open-source projects are using it, Vue.js, jsfiddle, etc.
0
Feb 12 '18
Sure but when I watch streams "legally" or download stuff "legally" and my ad blocker doesn't help out, sometimes a random ad site pop up. Many of those ad sites were using that style for their alerts.
0
Feb 12 '18
[deleted]
1
u/limonmonte Feb 12 '18
The first release of SweetAlert2 was 3 years ago: https://github.com/sweetalert2/sweetalert2/releases/tag/v0.0.1
0
Feb 12 '18
[deleted]
19
u/limonmonte Feb 12 '18
That behavior is customizable with the
backdropboolean parameter, set it tofalseto prevent disabling scrolling on a document.
38
u/[deleted] Feb 12 '18
I've been using this for years, pretty decent.
Unfortunate reddit auto-thumbnail...