Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure hidePrevented.bs.modal can be prevented #31696

Merged
merged 8 commits into from Sep 21, 2020
2 changes: 1 addition & 1 deletion js/src/modal.js
Expand Up @@ -234,7 +234,7 @@ class Modal {
const hideEventPrevented = $.Event(EVENT_HIDE_PREVENTED)

$(this._element).trigger(hideEventPrevented)
if (hideEventPrevented.defaultPrevented) {
if (hideEventPrevented.isDefaultPrevented()) {
return
}

Expand Down
38 changes: 38 additions & 0 deletions js/tests/unit/modal.js
Expand Up @@ -976,4 +976,42 @@ $(function () {
backdrop: 'static'
})
})

QUnit.test('should get modal-static class when clicking outside of modal-content if backdrop = static', function (assert) {
Johann-S marked this conversation as resolved.
Show resolved Hide resolved
assert.expect(1)
var done = assert.async()
var $modal = $('<div class="modal" data-backdrop="static"><div class="modal-dialog" style="transition-duration: 20ms;"/></div>').appendTo('#qunit-fixture')

$modal.on('shown.bs.modal', function () {
$modal.trigger('click')
setTimeout(function () {
assert.ok($modal.hasClass('modal-static'), 'has modal-static class')
done()
}, 0)
})
.bootstrapModal({
backdrop: 'static'
})
})

QUnit.test('should not get modal-static class when clicking outside of modal-content if backdrop = static and event is prevented', function (assert) {
assert.expect(1)
var done = assert.async()
var $modal = $('<div class="modal" data-backdrop="static"><div class="modal-dialog" style="transition-duration: 20ms;"/></div>').appendTo('#qunit-fixture')

$modal.on('hidePrevented.bs.modal', function (e) {
e.preventDefault()
Johann-S marked this conversation as resolved.
Show resolved Hide resolved
})

$modal.on('shown.bs.modal', function () {
$modal.trigger('click')
setTimeout(function () {
assert.notOk($modal.hasClass('modal-static'), 'should not have modal-static class')
done()
}, 0)
})
.bootstrapModal({
backdrop: 'static'
})
})
})