mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-10 07:37:27 +02:00
Don't hide modal when keyboard is set to false in modal's configuration (#32179)
* Don't hide modal when config.keyboard is false * Update unit test - Modal should not be closed when pressing esc key if keyboard = false and backdrop is 'static' Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
@@ -365,7 +365,11 @@ class Modal {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._config.backdrop === 'static') {
|
||||||
this._triggerBackdropTransition()
|
this._triggerBackdropTransition()
|
||||||
|
} else {
|
||||||
|
this.hide()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (animate) {
|
if (animate) {
|
||||||
@@ -404,7 +408,6 @@ class Modal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_triggerBackdropTransition() {
|
_triggerBackdropTransition() {
|
||||||
if (this._config.backdrop === 'static') {
|
|
||||||
const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE_PREVENTED)
|
const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE_PREVENTED)
|
||||||
if (hideEvent.defaultPrevented) {
|
if (hideEvent.defaultPrevented) {
|
||||||
return
|
return
|
||||||
@@ -430,9 +433,6 @@ class Modal {
|
|||||||
})
|
})
|
||||||
emulateTransitionEnd(this._element, modalTransitionDuration)
|
emulateTransitionEnd(this._element, modalTransitionDuration)
|
||||||
this._element.focus()
|
this._element.focus()
|
||||||
} else {
|
|
||||||
this.hide()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@@ -595,12 +595,11 @@ describe('Modal', () => {
|
|||||||
modal.show()
|
modal.show()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not close modal when escape key is pressed with keyboard = false and backdrop = static', done => {
|
it('should not close modal when escape key is pressed with keyboard = false', done => {
|
||||||
fixtureEl.innerHTML = '<div class="modal" data-bs-backdrop="static" data-bs-keyboard="false"><div class="modal-dialog"></div>'
|
fixtureEl.innerHTML = '<div class="modal"><div class="modal-dialog"></div></div>'
|
||||||
|
|
||||||
const modalEl = fixtureEl.querySelector('.modal')
|
const modalEl = fixtureEl.querySelector('.modal')
|
||||||
const modal = new Modal(modalEl, {
|
const modal = new Modal(modalEl, {
|
||||||
backdrop: 'static',
|
|
||||||
keyboard: false
|
keyboard: false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user