mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-18 10:52:19 +01:00
Fix prevented show event disables modals with fade class from being displayed again (#34085)
Fix modal, in case is faded, a prevented show event can cause show method to not be executed again.
This commit is contained in:
parent
136665903b
commit
b513a19003
@ -108,20 +108,20 @@ class Modal extends BaseComponent {
|
||||
return
|
||||
}
|
||||
|
||||
if (this._isAnimated()) {
|
||||
this._isTransitioning = true
|
||||
}
|
||||
|
||||
const showEvent = EventHandler.trigger(this._element, EVENT_SHOW, {
|
||||
relatedTarget
|
||||
})
|
||||
|
||||
if (this._isShown || showEvent.defaultPrevented) {
|
||||
if (showEvent.defaultPrevented) {
|
||||
return
|
||||
}
|
||||
|
||||
this._isShown = true
|
||||
|
||||
if (this._isAnimated()) {
|
||||
this._isTransitioning = true
|
||||
}
|
||||
|
||||
scrollBarHide()
|
||||
|
||||
document.body.classList.add(CLASS_NAME_OPEN)
|
||||
|
@ -203,6 +203,33 @@ describe('Modal', () => {
|
||||
modal.show()
|
||||
})
|
||||
|
||||
it('should be shown after the first call to show() has been prevented while fading is enabled ', done => {
|
||||
fixtureEl.innerHTML = '<div class="modal fade"><div class="modal-dialog"></div></div>'
|
||||
|
||||
const modalEl = fixtureEl.querySelector('.modal')
|
||||
const modal = new Modal(modalEl)
|
||||
|
||||
let prevented = false
|
||||
modalEl.addEventListener('show.bs.modal', e => {
|
||||
if (!prevented) {
|
||||
e.preventDefault()
|
||||
prevented = true
|
||||
|
||||
setTimeout(() => {
|
||||
modal.show()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
modalEl.addEventListener('shown.bs.modal', () => {
|
||||
expect(prevented).toBeTrue()
|
||||
expect(modal._isAnimated()).toBeTrue()
|
||||
done()
|
||||
})
|
||||
|
||||
modal.show()
|
||||
})
|
||||
|
||||
it('should set is transitioning if fade class is present', done => {
|
||||
fixtureEl.innerHTML = '<div class="modal fade"><div class="modal-dialog"></div></div>'
|
||||
|
||||
@ -210,7 +237,9 @@ describe('Modal', () => {
|
||||
const modal = new Modal(modalEl)
|
||||
|
||||
modalEl.addEventListener('show.bs.modal', () => {
|
||||
expect(modal._isTransitioning).toEqual(true)
|
||||
setTimeout(() => {
|
||||
expect(modal._isTransitioning).toEqual(true)
|
||||
})
|
||||
})
|
||||
|
||||
modalEl.addEventListener('shown.bs.modal', () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user