Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent overflowing static backdrop modal animation #30326

Merged
merged 13 commits into from Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion js/src/modal.js
Expand Up @@ -409,10 +409,23 @@ class Modal {
return
}

const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight
ysds marked this conversation as resolved.
Show resolved Hide resolved

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)
Johann-S marked this conversation as resolved.
Show resolved Hide resolved
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()
Expand Down
19 changes: 19 additions & 0 deletions js/tests/unit/modal.spec.js
Expand Up @@ -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>'

Expand Down