]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Backport #32179 (#32220)
authorRohit Sharma <rohit2sharma95@gmail.com>
Sat, 21 Nov 2020 20:14:28 +0000 (01:44 +0530)
committerGitHub <noreply@github.com>
Sat, 21 Nov 2020 20:14:28 +0000 (22:14 +0200)
Don't hide modal when `config.keyboard` is false

js/src/modal.js
js/tests/unit/modal.js

index 975a20be647b8019afd2095452c89a93bbaa3a54..ec1991da0ce9c27b9c5ef8e4af9287f3173645d2 100644 (file)
@@ -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) {
index 60c3cba9dddc355d8bb7c568e559dd8ac42134b7..a46b3d2deffebb115643ae36e8c8864d07aa00f0 100644 (file)
@@ -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 = $('<div class="modal" data-backdrop="static" data-keyboard="false"><div class="modal-dialog" /></div>').appendTo('#qunit-fixture')
+    var $modal = $('<div class="modal"><div class="modal-dialog" /></div>').appendTo('#qunit-fixture')
 
     $modal.on('shown.bs.modal', function () {
       $modal.trigger($.Event('keydown', {
@@ -955,7 +955,6 @@ $(function () {
         assert.strictEqual(false, true, 'should not hide the modal')
       })
       .bootstrapModal({
-        backdrop: 'static',
         keyboard: false
       })
   })