]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
ensure `hidePrevented.bs.modal` can be prevented (#31696)
authorJoakim Riedel <joakim.riedel@gmail.com>
Mon, 21 Sep 2020 11:41:40 +0000 (13:41 +0200)
committerGitHub <noreply@github.com>
Mon, 21 Sep 2020 11:41:40 +0000 (14:41 +0300)
js/src/modal.js
js/tests/unit/modal.js

index 311c369ebb1da795d007ed046b703c2f1b56bdd0..7b4228ffddf54aad9fa60314221ecbe977440604 100644 (file)
@@ -234,7 +234,7 @@ class Modal {
       const hideEventPrevented = $.Event(EVENT_HIDE_PREVENTED)
 
       $(this._element).trigger(hideEventPrevented)
-      if (hideEventPrevented.defaultPrevented) {
+      if (hideEventPrevented.isDefaultPrevented()) {
         return
       }
 
index c4e5a30565d0c94d247b768a0736903d346c8b45..60c3cba9dddc355d8bb7c568e559dd8ac42134b7 100644 (file)
@@ -976,4 +976,43 @@ $(function () {
         backdrop: 'static'
       })
   })
+
+  QUnit.test('should get modal-static class when clicking outside of modal-content if backdrop = static', function (assert) {
+    assert.expect(1)
+    var done = assert.async()
+    var $modal = $('<div class="modal" data-backdrop="static"><div class="modal-dialog" style="transition-duration: 20ms;"/></div>').appendTo('#qunit-fixture')
+
+    $modal.on('shown.bs.modal', function () {
+      $modal.trigger('click')
+      setTimeout(function () {
+        assert.ok($modal.hasClass('modal-static'), 'has modal-static class')
+        done()
+      }, 0)
+    })
+      .bootstrapModal({
+        backdrop: 'static'
+      })
+  })
+
+  QUnit.test('should not get modal-static class when clicking outside of modal-content if backdrop = static and event is prevented', function (assert) {
+    assert.expect(2)
+    var done = assert.async()
+    var $modal = $('<div class="modal" data-backdrop="static"><div class="modal-dialog" style="transition-duration: 20ms;"/></div>').appendTo('#qunit-fixture')
+
+    $modal.on('hidePrevented.bs.modal', function (e) {
+      assert.ok(true, 'should trigger hidePrevented event')
+      e.preventDefault()
+    })
+
+    $modal.on('shown.bs.modal', function () {
+      $modal.trigger('click')
+      setTimeout(function () {
+        assert.notOk($modal.hasClass('modal-static'), 'should not have modal-static class')
+        done()
+      }, 0)
+    })
+      .bootstrapModal({
+        backdrop: 'static'
+      })
+  })
 })