⨠A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies. đēđĻ
MIT License
Bot releases are hidden (Show)
window.onkeydown.toString()
(#727)đĨ This release is delivered because of the awesomeness of these people (ordered a-z): @acupajoe, @limonte, @samturrell, @toverux, @zenflow
useRejections
â ī¸ useRejections
is now false
default, set it to true
if you want backward compatibility with previous versions (<7.0.0
)
Before you were handling dismissals in the rejection handler: [JSFIDDLE â]
swal({
...
}).then(
value => {
// handle confirm
},
dismiss => {
// handle dismiss
}
).catch(swal.noop)
Now you should handle both confirmations and dismissals in the fulfillment handler: [JSFIDDLE â]
swal({
...
}).then(result => {
if (result.value) {
// handle confirm
console.log(result.value)
} else {
// handle dismiss, result.dismiss can be 'cancel', 'overlay', 'close', and 'timer'
console.log(result.dismiss)
}
})
In order to have painless backward compatibility with previous versions, use useRejections: true
[JSFIDDLE â]
swal({
useRejections: true // <<<<<<------- BACKWARD COMPATIBILITY WITH v6.x
}).then(
value => {
// handle confirm
},
dismiss => {
// handle dismiss
}
).catch(swal.noop)
âšī¸ Since we are not rejecting promise by default, .catch(swal.noop)
isn't needed anymore.
â ī¸ useRejections
is deprecated and will be removed in the next major release.
preConfirm
preConfirm
shouldn't reject a promise with an error message, instead it should show an error with swal.showValidationError(message)
and fulfill a promise:
Before:
preConfirm: (email) => {
return new Promise((resolve, reject) => {
if (email === '[email protected]') {
reject('This email is already taken.')
}
resolve()
})
}
After:
preConfirm: (email) => {
return new Promise((resolve) => {
if (email === '[email protected]') {
swal.showValidationError('This email is already taken.')
}
resolve()
})
}
inputValidator
inputValidator
shouldn't reject a promise with an error message, instead, it should fulfill a promise with an error string:
Before:
inputValidator: (email) => {
return new Promise((resolve, reject) => {
if (email === '[email protected]') {
reject('This email is already taken.')
}
resolve()
})
}
After:
preConfirm: (email) => {
return new Promise((resolve) => {
if (email === '[email protected]') {
resolve('This email is already taken.')
}
resolve()
})
}
dist/sweetalert2.all.js
(#692 #612 #422).
import swal from 'sweetalert2/dist/sweetalert2.all.js'
import swal from 'sweetalert2'
â ī¸ It's not needed to import CSS styles separately, they are included in dist/sweetalert2.all.js
.
async/await
(#485 #700)const {value: name} = await swal({text: 'What is your name?', input: 'text'})
const {value: location} = await swal({text: 'Where are you from?', input: 'text'})
swal(`Hi ${name}, from ${location}!`)
swal({
text: 'Your work has been saved',
toast: true
})
backdrop
parameter, default true
(#680 #681)swal({
text: 'I will not add a backdrop to the document',
backdrop: false
})
These parameter are now deprecated and will be removed in the next major release:
useRejections
expectRejections
input: 'textarea'
(https://github.com/limonte/sweetalert2/issues/702)Special thanks to @samturrell đģ
margin: auto
where position isn't specified (fix https://github.com/limonte/sweetalert2/issues/679)all.min.js
with .js
+ .css
, there's opened issue which should be fixed before releasing v7.0.0
: https://github.com/limonte/sweetalert2/issues/673
puppeteer
in visual screenshots to 0.12.0 (#682)swal.getButtonsWrapper()
missing docs and test (https://github.com/limonte/sweetalert2/commit/be80a18fe23ec3eb46a77dbdfd74327245fcd31a)swal.version
in dist/sweetalert2.all.min.js
(https://github.com/limonte/sweetalert2/commit/5d63afa83d11ab1d306e9912cba3598c49632b99)sweetalert.all.min.js
(https://github.com/limonte/sweetalert2/commit/80fe30920fd300923701415f57a4da9d84a75e15)Published by limonte about 7 years ago
dist/sweetalert2.all.min.js
with CSS bundled into JS (#644)This release was delivered by ninja master @samturrell đģ
You can now import all-in-one file with JS + CSS:
import swal from 'sweetalert2/dist/sweetalert2.all.min.js'
focusConfirm
parameter (#620), true
by default for backwards compatibility. If set to false
, the first element in tab order inside the modal will be focused, see the example: https://limonte.github.io/sweetalert2/#custom-html
closeButtonAriaLabel
parameter (#621)onOpen
and showLoading()
in timer example:aria-busy
state for loading state (#622)aria-invalid
to indicate an invalid input field (#619)imageAlt
(#618)aria-label
support for buttons: confirmButtonAriaLabel
and cancelButtonAriaLabel
(#608)gemini
tests because of their instability, visual test will be implemented with puppeteer
in one of upcoming releasesshowLoaderOnConfirm
is true
, but preConfirm
is not defined (conected to #600)CODE_OF_CONDUCT.md
tabindex
(#598)