r/webdev • • Feb 15 '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/
296 Upvotes

63 comments sorted by

23

u/[deleted] Feb 15 '18 edited Feb 15 '18

It starts without body scrollbar, then, after opening popup, scrollbar shows after 0.5 second and popup jumps a little to the left.

But very good job, I love it :)

(Windows 10, Chrome 64.0.3282.167).

(Video, sorry for quality: https://gfycat.com/SilverWaryCod)

21

u/limonmonte Feb 15 '18

Thanks for reporting, fixed in the latest release! Could you please verify it works for you as well: https://sweetalert2.github.io/

6

u/[deleted] Feb 15 '18

That was quick ;-) Yea, works great. Thanks!

2

u/limonmonte Feb 15 '18

Lovely, thanks again!

4

u/jammy-git Feb 15 '18

Maybe this is getting too complex, but I'd prefer a solution that didn't change whether the scollbar was hidden or not. At the moment, I view the page and there is a vertical scollbar - open the modal and the scrollbar disappears and the whole content jumps over. Could you not disable scrolling without interfering whether the scrollbar is visible or not?

5

u/limonmonte Feb 15 '18

Sure, there's the backdrop option, if it's set to false, the scrollbar won't be touched.

1

u/zildjian Feb 15 '18

What did you use for generating that video?

1

u/[deleted] Feb 15 '18

ShareX.

19

u/fuckin_ziggurats Feb 15 '18

Hasn't this existed for quite a while? Is there something new in the latest versions?

18

u/limonmonte Feb 15 '18

The plugin has moved from my personal GitHub account to the organization, the URL changed from https://limonte.github.io/sweetalert2/ to https://sweetalert2.github.io/

In scope of SweetAlert2 organization we have several repositories:

3

u/fuckin_ziggurats Feb 15 '18

Ahh I see. Thanks for the info

9

u/[deleted] Feb 15 '18

It screws up scroll position on mobile when it opens

5

u/limonmonte Feb 15 '18

Thanks for reporting! Could you please specify the device and browser you're using?

10

u/[deleted] Feb 15 '18

Using the Reddit app embedded browser on an iPhone X with the latest OS

7

u/limonmonte Feb 15 '18

Reddit app embedded browser

Reported: https://github.com/sweetalert2/sweetalert2/issues/920

This isn't the issue in iOS/Safari or iOS/Chrome, but still we'll try to fix it as soon as possible.

Thanks again!

4

u/fgutz Feb 15 '18

This isn't the issue in iOS/Safari or iOS/Chrome

Weird. iOS Chrome and the Reddit App embedded browser should be using the same rendering engine (WKWebView) because iOS does not allow external browsers. All third party browsers on iOS are just wrappers over WKWebView, or the older UIWebView.

4

u/limonmonte Feb 15 '18

Weird indeed, I have no idea how to debug Reddit App embedded browser :)

5

u/MacGuyverism Feb 15 '18

Just try stuff until it works, it's not like we're paying you so you can take your time.

4

u/limonmonte Feb 15 '18

Fixed in the latest release, please check it out: https://sweetalert2.github.io

2

u/MacGuyverism Feb 16 '18

Wow! My suggestion was way more efficient that I thought it would be!

2

u/Mike Feb 15 '18

Works fine for me on my 8 plus

2

u/limonmonte Feb 15 '18

Fixed in the latest release, please check it out: https://sweetalert2.github.io

2

u/[deleted] Feb 16 '18

Better, but now the backdrop doesn’t cover the entire bottom portion of the screen. Also I’m able to scroll the underlying page while the modal is opened.

4

u/benz0pheles Feb 15 '18

Been using this for a long time now. Just wanted to say thank you for doing us a solid

2

u/limonmonte Feb 15 '18

Credits to the community and devs who reporting issues and sending their PRs!

4

u/robhybrid Feb 15 '18

I use this all the time, and I love it. The only issue I have with it, is that it's hard to do something more interactive outside of the very specific use cases you have defined.

I'd like to be able to load a React component in the same way you can define HTML. It's possible to load a component into the modal using a setTimeout callback. It'd be nice to have a callback for when the modal is ready to be modified. I'm thinking of writing a PR for injecting React components.

5

u/limonmonte Feb 15 '18

I made such PR a couple of weeks ago: https://github.com/sweetalert2/sweetalert2/pull/795 and after some discussion, it was rejected. We decided to keep the plugin by itself framework-agnostic.

We do have plans though to release the official React integration (we already have the beautiful integration with Angular: https://github.com/sweetalert2/ngx-sweetalert2).

Right now you can use React components like this:

swal({
  onOpen: () => ReactDOM.render(
    <div>Hello, React</div>,
    swal.getContent()
  ),
  onClose: () => ReactDOM.unmountComponentAtNode(swal.getContent())
})

2

u/janitux Feb 15 '18

Can we use this over a bootstrap modal? We need bigger alerts on an app and this seems the perfect fit!

2

u/limonmonte Feb 15 '18

Sure, here's the Bootstrap 4 + SweetAlert2 example: https://jsfiddle.net/limon/hz6un8s0/

2

u/chrissilich Feb 15 '18

Wait, toast?

3

u/limonmonte Feb 15 '18

This feature was added recently, we didn't update the examples page yet, but yes, just add the toast: true :)

3

u/chrissilich Feb 15 '18

I was not aware that those were called toast, and the other ones you mentioned in the title were built in to vanilla JS, so I thought there was some vanilla toast() function I’d missed all these years.

2

u/hartator Feb 15 '18

Really cool. I wonder if it can make sense to just replace alert() in my project.

2

u/limonmonte Feb 15 '18

Depends on your project, but I know a couple of open-source projects with using SweetAlert2 just to replace alerts.

2

u/the_wander Feb 15 '18

This is really, well, sweet. How does it handle embedded videos? Can it handle HTML video?

2

u/limonmonte Feb 15 '18

Sure, why not, here's the example: https://jsfiddle.net/ad3quksn/443/

1

u/the_wander Feb 15 '18

Hey, awesome. Going to give this a shot. If it works as well as advertised, I'll throw you some cash. Thanks.

2

u/danhakimi Feb 16 '18

This is cool, but to my eye, most of these boxes look a little big for general purposes. I think, generally, if I'm being alerted about... whatever, , I have no need for a ton of negative space of fun animations or big text, I just want a small box that grabs my attention (mostly via the contrast), tells me what I need to know, and gets my conversation.

Of course, browser based alerts suck, and your shit is more customizable with a better button and without invoking the horror most people feel when they're trying to kill an ad that just won't die... So yeah, it looks like your alerts are the shit, I'm just giving my two cents, maybe a smaller box by default would get the job did well.

2

u/limonmonte Feb 16 '18

Thanks for your honest opinion :)

Reported: https://github.com/sweetalert2/sweetalert2/issues/922

Expect the Minimal theme next week.

2

u/danhakimi Feb 16 '18

Awesome! Glad to hear my feedback was helpful!

2

u/dikiaap Feb 16 '18

Is it supposed to use border on the button for the first time pop-up?

But when I click on the white background, I prefer this one.

1

u/limonmonte Feb 16 '18

It's possible to remove the outline from buttons, but PLEASE DO NOT DO THAT.

There's a reason for that ugly outline: https://stackoverflow.com/a/25298082/1331425

By removing it you're killing the keyboard a11y of your app. People with vision disabilities, as well as keyboard-ninjas, will hate you for that.

We working hard to make this plugin accessible to all users, by removing buttons outline you simply ruin our effort.

3

u/fbg13 Feb 16 '18

Is it supposed to use border on the button

That's because the button is focused, you can use enter to use it.

3

u/gigastack Feb 15 '18

Sweet.

Seriously though, this is very cool.

1

u/[deleted] Feb 15 '18

How do I get it?

5

u/limonmonte Feb 15 '18

2

u/[deleted] Feb 15 '18

And it works on Android?

3

u/limonmonte Feb 15 '18

Sure it does!

2

u/_Include Feb 15 '18

I love it! Keep up the good work, definitely going to use it in the future.

2

u/careseite discord admin Feb 15 '18

Neat. Probably going to use this in my upcoming page :)

2

u/[deleted] Feb 15 '18

Nice work, just in time for a project I'm building!

2

u/zebbadee Feb 15 '18

Fantastic project! Thanks!

2

u/04fuxake Feb 16 '18

Not to be confused with SweetAlert 2.0.

-1

u/[deleted] Feb 15 '18

So many catch words in the title.... r/titlegore!

0

u/[deleted] Feb 15 '18

[deleted]

21

u/limonmonte Feb 15 '18

This is the popular fork :) It's called SweetAlert2, the original SweetAlert had (and still have) issues with the maintenance.

9

u/birjolaxew Feb 15 '18

I'd also like to point out that /u/limonmonte has put in a huge amount of work keeping the fork maintained. I, and several others, have contributed here and there, but Limonte has been absolutely tireless in keeping the project going. Massive props to him.

0

u/[deleted] Feb 15 '18

[deleted]

4

u/limonmonte Feb 15 '18

I am. One of :) There are several core collaborators: https://github.com/sweetalert2/sweetalert2#collaborators Without them, this plugin wouldn't be so sexy.

0

u/[deleted] Feb 16 '18

[deleted]

1

u/limonmonte Feb 16 '18

Are you using the latest version?

2

u/[deleted] Feb 16 '18

Nevermind, I solved the solution by placing my script inside body tags. I feel this shouldn't be required.

0

u/[deleted] Feb 15 '18

[deleted]

1

u/limonmonte Feb 15 '18

thanks for reporting this! Could you please record that jankiness because I can't reproduce it.

0

u/[deleted] Feb 16 '18

[deleted]

1

u/limonmonte Feb 17 '18

Many thanks for specifying browser/OS and screen-recording.

I reported the issue: https://github.com/sweetalert2/sweetalert2/issues/927 we'll try to fix it asap

1

u/imguralbumbot Feb 16 '18

Hi, I'm a bot for linking direct images of albums with only 1 image

https://i.imgur.com/5Htq6gk.mp4

Source | Why? | Creator | ignoreme | deletthis