Skip to content
Permalink
Browse files

fix: double-click on backdrop should close popup once (#1579)

  • Loading branch information...
limonte committed May 7, 2019
1 parent 81c0a0d commit 78d2d2a04360c3da2e69ef99b51d2a4bb13a09f3
Showing with 28 additions and 10 deletions.
  1. +1 −1 src/instanceMethods/_main.js
  2. +1 −1 src/instanceMethods/close.js
  3. +23 −5 test/qunit/outside-click.js
  4. +3 −3 test/qunit/tests.js
@@ -319,7 +319,7 @@ export function _main (userParams) {
}
}

if (globalState.keydownHandlerAdded) {
if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, { capture: globalState.keydownListenerCapture })
globalState.keydownHandlerAdded = false
}
@@ -69,7 +69,7 @@ export function close (resolveValue) {
const onClose = innerParams.onClose
const onAfterClose = innerParams.onAfterClose

if (!popup) {
if (!popup || dom.hasClass(popup, swalClasses.hide)) {
return
}

@@ -1,4 +1,4 @@
const { $, Swal, SwalWithoutAnimation, dispatchCustomEvent, TIMEOUT } = require('./helpers')
const { Swal, SwalWithoutAnimation, dispatchCustomEvent, TIMEOUT } = require('./helpers')
const sinon = require('sinon/pkg/sinon')

const simulateMouseEvent = (x, y, eventType) => {
@@ -17,7 +17,25 @@ QUnit.test('backdrop click', (assert) => {
done()
})

$('.swal2-container').click()
Swal.getContainer().click()
})

QUnit.test('double backdrop click', (assert) => {
const done = assert.async()
const onAfterClose = sinon.fake()

Swal.fire({
title: 'onAfterClose should be triggered once',
onAfterClose
})

Swal.getContainer().click()
Swal.getContainer().click()

setTimeout(() => {
assert.ok(onAfterClose.calledOnce)
done()
}, 500)
})

QUnit.test('popup mousedown, backdrop mouseup', (assert) => {
@@ -56,7 +74,7 @@ QUnit.test('allowOutsideClick: false', (assert) => {
allowOutsideClick: false
})

$('.swal2-container').click()
Swal.getContainer().click()

setTimeout(() => {
assert.ok(Swal.isVisible())
@@ -77,12 +95,12 @@ QUnit.test('allowOutsideClick: () => !swal.isLoading()', (assert) => {

Swal.showLoading()

$('.swal2-container').click()
Swal.getContainer().click()

setTimeout(() => {
assert.ok(Swal.isVisible())
Swal.hideLoading()
$('.swal2-container').click()
Swal.getContainer().click()
}, TIMEOUT)
})

@@ -516,7 +516,7 @@ QUnit.test('onAfterClose', (assert) => {
},
onAfterClose: () => {
assert.ok(onCloseFinished)
assert.notOk($('.swal2-container'))
assert.notOk(Swal.getContainer())
done()
}
})
@@ -532,7 +532,7 @@ QUnit.test('onClose', (assert) => {
title: 'onClose test',
onClose: (_modal) => {
assert.ok(modal, _modal)
assert.ok($('.swal2-container'))
assert.ok(Swal.getContainer())
done()
}
})
@@ -675,7 +675,7 @@ QUnit.test('backdrop accepts css background param', (assert) => {
title: 'I have no backdrop',
backdrop: false
})
assert.notOk($('.swal2-container').style.background)
assert.notOk(Swal.getContainer().style.background)

let backdrop = 'rgb(123, 123, 123)'
Swal.fire({

0 comments on commit 78d2d2a

Please sign in to comment.
You can’t perform that action at this time.