mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-21 18:54:30 +01:00
Fix modal event listeners (#37128)
* Fix modal event listeners (#37126) Co-authored-by: GeoSot <geo.sotis@gmail.com>
This commit is contained in:
parent
aedd7fb9de
commit
6f65df4fae
@ -223,9 +223,9 @@ class Modal extends BaseComponent {
|
|||||||
})
|
})
|
||||||
|
|
||||||
EventHandler.on(this._element, EVENT_MOUSEDOWN_DISMISS, event => {
|
EventHandler.on(this._element, EVENT_MOUSEDOWN_DISMISS, event => {
|
||||||
EventHandler.one(this._element, EVENT_CLICK_DISMISS, event2 => {
|
|
||||||
// a bad trick to segregate clicks that may start inside dialog but end outside, and avoid listen to scrollbar clicks
|
// a bad trick to segregate clicks that may start inside dialog but end outside, and avoid listen to scrollbar clicks
|
||||||
if (this._dialog.contains(event.target) || this._dialog.contains(event2.target)) {
|
EventHandler.one(this._element, EVENT_CLICK_DISMISS, event2 => {
|
||||||
|
if (this._element !== event.target || this._element !== event2.target) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -734,6 +734,36 @@ describe('Modal', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should not close modal when clicking on an element removed from modal content', () => {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
fixtureEl.innerHTML = [
|
||||||
|
'<div class="modal">',
|
||||||
|
' <div class="modal-dialog">',
|
||||||
|
' <button class="btn">BTN</button>',
|
||||||
|
' </div>',
|
||||||
|
'</div>'
|
||||||
|
].join('')
|
||||||
|
|
||||||
|
const modalEl = fixtureEl.querySelector('.modal')
|
||||||
|
const buttonEl = modalEl.querySelector('.btn')
|
||||||
|
const modal = new Modal(modalEl)
|
||||||
|
|
||||||
|
const spy = spyOn(modal, 'hide')
|
||||||
|
buttonEl.addEventListener('click', () => {
|
||||||
|
buttonEl.remove()
|
||||||
|
})
|
||||||
|
|
||||||
|
modalEl.addEventListener('shown.bs.modal', () => {
|
||||||
|
modalEl.dispatchEvent(createEvent('mousedown'))
|
||||||
|
buttonEl.click()
|
||||||
|
expect(spy).not.toHaveBeenCalled()
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
|
||||||
|
modal.show()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('should do nothing is the modal is not shown', () => {
|
it('should do nothing is the modal is not shown', () => {
|
||||||
fixtureEl.innerHTML = '<div class="modal"><div class="modal-dialog"></div></div>'
|
fixtureEl.innerHTML = '<div class="modal"><div class="modal-dialog"></div></div>'
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user