From: Rohit Sharma Date: Sat, 21 Nov 2020 20:14:28 +0000 (+0530) Subject: Backport #32179 (#32220) X-Git-Tag: v4.6.0~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfb773d64be5f3c07628bb6e3f1295fd854c4514;p=thirdparty%2Fbootstrap.git Backport #32179 (#32220) Don't hide modal when `config.keyboard` is false --- diff --git a/js/src/modal.js b/js/src/modal.js index 975a20be64..ec1991da0c 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -230,39 +230,35 @@ class Modal { } _triggerBackdropTransition() { - if (this._config.backdrop === 'static') { - const hideEventPrevented = $.Event(EVENT_HIDE_PREVENTED) + const hideEventPrevented = $.Event(EVENT_HIDE_PREVENTED) - $(this._element).trigger(hideEventPrevented) - if (hideEventPrevented.isDefaultPrevented()) { - return - } + $(this._element).trigger(hideEventPrevented) + if (hideEventPrevented.isDefaultPrevented()) { + return + } - const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight + const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight - if (!isModalOverflowing) { - this._element.style.overflowY = 'hidden' - } + if (!isModalOverflowing) { + this._element.style.overflowY = 'hidden' + } - this._element.classList.add(CLASS_NAME_STATIC) + this._element.classList.add(CLASS_NAME_STATIC) - const modalTransitionDuration = Util.getTransitionDurationFromElement(this._dialog) - $(this._element).off(Util.TRANSITION_END) + const modalTransitionDuration = Util.getTransitionDurationFromElement(this._dialog) + $(this._element).off(Util.TRANSITION_END) - $(this._element).one(Util.TRANSITION_END, () => { - this._element.classList.remove(CLASS_NAME_STATIC) - if (!isModalOverflowing) { - $(this._element).one(Util.TRANSITION_END, () => { - this._element.style.overflowY = '' - }) - .emulateTransitionEnd(this._element, modalTransitionDuration) - } - }) - .emulateTransitionEnd(modalTransitionDuration) - this._element.focus() - } else { - this.hide() - } + $(this._element).one(Util.TRANSITION_END, () => { + this._element.classList.remove(CLASS_NAME_STATIC) + if (!isModalOverflowing) { + $(this._element).one(Util.TRANSITION_END, () => { + this._element.style.overflowY = '' + }) + .emulateTransitionEnd(this._element, modalTransitionDuration) + } + }) + .emulateTransitionEnd(modalTransitionDuration) + this._element.focus() } _showElement(relatedTarget) { @@ -400,7 +396,11 @@ class Modal { return } - this._triggerBackdropTransition() + if (this._config.backdrop === 'static') { + this._triggerBackdropTransition() + } else { + this.hide() + } }) if (animate) { diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index 60c3cba9dd..a46b3d2def 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -934,10 +934,10 @@ $(function () { }) }) - QUnit.test('should not close modal when escape key is pressed with keyboard = false and backdrop = static', function (assert) { + QUnit.test('should not close modal when escape key is pressed with keyboard = false', function (assert) { assert.expect(1) var done = assert.async() - var $modal = $('