From: alpadev <2838324+alpadev@users.noreply.github.com> Date: Sun, 25 Jul 2021 17:36:11 +0000 (+0200) Subject: fix(modal): change the order we return from show() method (#34087) X-Git-Tag: v4.6.1~33 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b010a6f9f4ea3dda08a4792e1367730ddcf8752d;p=thirdparty%2Fbootstrap.git fix(modal): change the order we return from show() method (#34087) In case of a modal with fading enabled, a prevented show event can cause show to not showing the modal anymore. See #34055 Co-authored-by: XhmikosR --- diff --git a/js/src/modal.js b/js/src/modal.js index 2e3017024e..a23bfc1ba6 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 a46b3d2def..f2c60684b9 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 = $('