]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Revert backdrop utilization, handling clicks over modal (#36324)
authorGeoSot <geo.sotis@gmail.com>
Fri, 13 May 2022 04:20:04 +0000 (07:20 +0300)
committerGitHub <noreply@github.com>
Fri, 13 May 2022 04:20:04 +0000 (21:20 -0700)
* refactor(Modal.js): stop using backdrop class to handle clicks over modal

* Revert #35554 and backdrop callback usage
  Explanation: In order to bypass `.modal`, was applied a css rule `pointer-events:none` which caused the side effect, and user couldn't scroll "long content modals"

* Update .bundlewatch.config.json

Co-authored-by: Mark Otto <markd.otto@gmail.com>
.bundlewatch.config.json
js/src/modal.js
js/tests/unit/modal.spec.js
scss/_modal.scss

index cb37f08fdb4ddbfbdac4815705c2f1f6ff06e67f..c4e9db4b1dda432e4210b8cf3797b31ad8e08053 100644 (file)
@@ -34,7 +34,7 @@
     },
     {
       "path": "./dist/js/bootstrap.bundle.js",
-      "maxSize": "42.75 kB"
+      "maxSize": "43.0 kB"
     },
     {
       "path": "./dist/js/bootstrap.bundle.min.js",
@@ -42,7 +42,7 @@
     },
     {
       "path": "./dist/js/bootstrap.esm.js",
-      "maxSize": "27.5 kB"
+      "maxSize": "27.75 kB"
     },
     {
       "path": "./dist/js/bootstrap.esm.min.js",
index ea8e0a0463b70df75f9ff5b520d3045a189190fc..cb6c5e627cf6b3a6b277c4cc711fbb51d8da2f02 100644 (file)
@@ -30,6 +30,7 @@ const EVENT_HIDDEN = `hidden${EVENT_KEY}`
 const EVENT_SHOW = `show${EVENT_KEY}`
 const EVENT_SHOWN = `shown${EVENT_KEY}`
 const EVENT_RESIZE = `resize${EVENT_KEY}`
+const EVENT_CLICK_DISMISS = `click.dismiss${EVENT_KEY}`
 const EVENT_KEYDOWN_DISMISS = `keydown.dismiss${EVENT_KEY}`
 const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
 
@@ -152,22 +153,9 @@ class Modal extends BaseComponent {
 
   // Private
   _initializeBackDrop() {
-    const clickCallback = () => {
-      if (this._config.backdrop === 'static') {
-        this._triggerBackdropTransition()
-        return
-      }
-
-      this.hide()
-    }
-
-    // 'static' option will be translated to true, and booleans will keep their value
-    const isVisible = Boolean(this._config.backdrop)
-
     return new Backdrop({
-      isVisible,
-      isAnimated: this._isAnimated(),
-      clickCallback: isVisible ? clickCallback : null
+      isVisible: Boolean(this._config.backdrop), // 'static' option will be translated to true, and booleans will keep their value,
+      isAnimated: this._isAnimated()
     })
   }
 
@@ -232,6 +220,21 @@ class Modal extends BaseComponent {
         this._adjustDialog()
       }
     })
+
+    EventHandler.on(this._element, EVENT_CLICK_DISMISS, event => {
+      if (event.target !== event.currentTarget) { // click is inside modal-dialog
+        return
+      }
+
+      if (this._config.backdrop === 'static') {
+        this._triggerBackdropTransition()
+        return
+      }
+
+      if (this._config.backdrop) {
+        this.hide()
+      }
+    })
   }
 
   _hideModal() {
index bf26377fe87fdd93438a8401147d6331e4358965..a127792344a0a89f89d5c3fd0a3a68d294a04b83 100644 (file)
@@ -642,11 +642,8 @@ describe('Modal', () => {
         modalEl.addEventListener('shown.bs.modal', () => {
           const spy = spyOn(modal, '_queueCallback').and.callThrough()
 
-          const mouseOverEvent = createEvent('mousedown')
-          const backdrop = document.querySelector('.modal-backdrop')
-
-          backdrop.dispatchEvent(mouseOverEvent)
-          backdrop.dispatchEvent(mouseOverEvent)
+          modalEl.click()
+          modalEl.click()
 
           setTimeout(() => {
             expect(spy).toHaveBeenCalledTimes(1)
@@ -714,8 +711,7 @@ describe('Modal', () => {
         const modalEl = fixtureEl.querySelector('.modal')
         const modal = new Modal(modalEl)
         modalEl.addEventListener('shown.bs.modal', () => {
-          const mouseOverEvent = createEvent('mousedown')
-          document.querySelector('.modal-backdrop').dispatchEvent(mouseOverEvent)
+          modalEl.click()
         })
 
         modalEl.addEventListener('hidden.bs.modal', () => {
index 39f4f2edf1c3072e96f08f0a9fa94e53875c8e79..a25af574148d33d275cd04ff0a048319e7883ce1 100644 (file)
@@ -41,7 +41,6 @@
   height: 100%;
   overflow-x: hidden;
   overflow-y: auto;
-  pointer-events: none;
   // Prevent Chrome on Windows from adding a focus outline. For details, see
   // https://github.com/twbs/bootstrap/pull/10951.
   outline: 0;