diff options
| -rw-r--r-- | js/src/modal.js | 10 | ||||
| -rw-r--r-- | js/tests/unit/modal.js | 26 |
2 files changed, 31 insertions, 5 deletions
diff --git a/js/src/modal.js b/js/src/modal.js index 2e3017024..a23bfc1ba 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -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() diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index a46b3d2de..f2c60684b 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -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() |
