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

v4: Fix prevented show event disables modals with fade class from being displayed again #34087

Merged
merged 2 commits into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions js/src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,22 @@ class Modal {
return
}

if ($(this._element).hasClass(CLASS_NAME_FADE)) {
this._isTransitioning = true
}

const showEvent = $.Event(EVENT_SHOW, {
relatedTarget
})

$(this._element).trigger(showEvent)

if (this._isShown || showEvent.isDefaultPrevented()) {
if (showEvent.isDefaultPrevented()) {
return
}

this._isShown = true

if ($(this._element).hasClass(CLASS_NAME_FADE)) {
this._isTransitioning = true
}

this._checkScrollbar()
this._setScrollbar()

Expand Down
26 changes: 26 additions & 0 deletions js/tests/unit/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,32 @@ $(function () {
.bootstrapModal('show')
})

QUnit.test('should be shown after the first call to show() has been prevented while fading is enabled', function (assert) {
assert.expect(2)
var done = assert.async()

var $el = $('<div class="modal fade"><div class="modal-dialog" style="transition-duration: 20ms;"/></div>').appendTo('#qunit-fixture')

var prevented = false
$el
.on('show.bs.modal', function (e) {
if (!prevented) {
e.preventDefault()
prevented = true

setTimeout(function () {
$el.bootstrapModal('show')
})
}
})
.on('shown.bs.modal', function () {
assert.ok(prevented, 'show prevented')
assert.ok($el.hasClass('fade'))
done()
})
.bootstrapModal('show')
})

QUnit.test('should hide modal when hide is called', function (assert) {
assert.expect(3)
var done = assert.async()
Expand Down