]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Prevent overflowing static backdrop modal animation (#30326)
authorShohei Yoshida <ysds.code@gmail.com>
Thu, 25 Jun 2020 08:35:53 +0000 (17:35 +0900)
committerGitHub <noreply@github.com>
Thu, 25 Jun 2020 08:35:53 +0000 (11:35 +0300)
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
js/src/modal.js
js/tests/unit/modal.spec.js

index 0d15041bd77e6f4b3335169303e62cf8e65173d6..8c6617650d26459cf7ad3d881df4d2a9a12793df 100644 (file)
@@ -409,10 +409,23 @@ class Modal {
         return
       }
 
+      const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight
+
+      if (!isModalOverflowing) {
+        this._element.style.overflowY = 'hidden'
+      }
+
       this._element.classList.add(CLASS_NAME_STATIC)
-      const modalTransitionDuration = getTransitionDurationFromElement(this._element)
+      const modalTransitionDuration = getTransitionDurationFromElement(this._dialog)
+      EventHandler.off(this._element, TRANSITION_END)
       EventHandler.one(this._element, TRANSITION_END, () => {
         this._element.classList.remove(CLASS_NAME_STATIC)
+        if (!isModalOverflowing) {
+          EventHandler.one(this._element, TRANSITION_END, () => {
+            this._element.style.overflowY = ''
+          })
+          emulateTransitionEnd(this._element, modalTransitionDuration)
+        }
       })
       emulateTransitionEnd(this._element, modalTransitionDuration)
       this._element.focus()
index afb8f2c2d401db5a054fdeac1c305edb88443df2..253f9351359727f27f2a6156ba17fc2294695e99 100644 (file)
@@ -626,6 +626,25 @@ describe('Modal', () => {
       modal.show()
     })
 
+    it('should not overflow when clicking outside of modal-content if backdrop = static', done => {
+      fixtureEl.innerHTML = '<div class="modal" data-backdrop="static"><div class="modal-dialog" style="transition-duration: 20ms;"></div></div>'
+
+      const modalEl = fixtureEl.querySelector('.modal')
+      const modal = new Modal(modalEl, {
+        backdrop: 'static'
+      })
+
+      modalEl.addEventListener('shown.bs.modal', () => {
+        modalEl.click()
+        setTimeout(() => {
+          expect(modalEl.clientHeight === modalEl.scrollHeight).toEqual(true)
+          done()
+        }, 20)
+      })
+
+      modal.show()
+    })
+
     it('should not adjust the inline body padding when it does not overflow', done => {
       fixtureEl.innerHTML = '<div class="modal"><div class="modal-dialog"></div></div>'