Skip to content

Commit fb4efb4

Browse files
ysdsXhmikosR
andauthored
Prevent overflowing static backdrop modal animation (#30326)
Co-authored-by: XhmikosR <[email protected]>
1 parent 9f173ae commit fb4efb4

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

js/src/modal.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,23 @@ class Modal {
409409
return
410410
}
411411

412+
const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight
413+
414+
if (!isModalOverflowing) {
415+
this._element.style.overflowY = 'hidden'
416+
}
417+
412418
this._element.classList.add(CLASS_NAME_STATIC)
413-
const modalTransitionDuration = getTransitionDurationFromElement(this._element)
419+
const modalTransitionDuration = getTransitionDurationFromElement(this._dialog)
420+
EventHandler.off(this._element, TRANSITION_END)
414421
EventHandler.one(this._element, TRANSITION_END, () => {
415422
this._element.classList.remove(CLASS_NAME_STATIC)
423+
if (!isModalOverflowing) {
424+
EventHandler.one(this._element, TRANSITION_END, () => {
425+
this._element.style.overflowY = ''
426+
})
427+
emulateTransitionEnd(this._element, modalTransitionDuration)
428+
}
416429
})
417430
emulateTransitionEnd(this._element, modalTransitionDuration)
418431
this._element.focus()

js/tests/unit/modal.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,25 @@ describe('Modal', () => {
626626
modal.show()
627627
})
628628

629+
it('should not overflow when clicking outside of modal-content if backdrop = static', done => {
630+
fixtureEl.innerHTML = '<div class="modal" data-backdrop="static"><div class="modal-dialog" style="transition-duration: 20ms;"></div></div>'
631+
632+
const modalEl = fixtureEl.querySelector('.modal')
633+
const modal = new Modal(modalEl, {
634+
backdrop: 'static'
635+
})
636+
637+
modalEl.addEventListener('shown.bs.modal', () => {
638+
modalEl.click()
639+
setTimeout(() => {
640+
expect(modalEl.clientHeight === modalEl.scrollHeight).toEqual(true)
641+
done()
642+
}, 20)
643+
})
644+
645+
modal.show()
646+
})
647+
629648
it('should not adjust the inline body padding when it does not overflow', done => {
630649
fixtureEl.innerHTML = '<div class="modal"><div class="modal-dialog"></div></div>'
631650

0 commit comments

Comments
 (0)