From: Giovanni Mendoza Date: Fri, 10 Jan 2020 09:06:12 +0000 (-0600) Subject: Close modal with keyboard=true & backdrop=static (#29986) X-Git-Tag: v5.0.0-alpha1~527 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=954a0b1e6a206e4df910d4799d013f4388a2ef40;p=thirdparty%2Fbootstrap.git Close modal with keyboard=true & backdrop=static (#29986) * Close modal with keyboard=true & backdrop=static --- diff --git a/js/src/modal.js b/js/src/modal.js index e2b711e5be..48ff5b8540 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -306,9 +306,12 @@ class Modal { } _setEscapeEvent() { - if (this._isShown && this._config.keyboard) { + if (this._isShown) { EventHandler.on(this._element, Event.KEYDOWN_DISMISS, event => { - if (event.which === ESCAPE_KEYCODE) { + if (this._config.keyboard && event.which === ESCAPE_KEYCODE) { + event.preventDefault() + this.hide() + } else if (!this._config.keyboard && event.which === ESCAPE_KEYCODE) { this._triggerBackdropTransition() } }) diff --git a/js/tests/unit/modal.spec.js b/js/tests/unit/modal.spec.js index 2edef22b2c..b4923ab3f4 100644 --- a/js/tests/unit/modal.spec.js +++ b/js/tests/unit/modal.spec.js @@ -567,6 +567,64 @@ describe('Modal', () => { modal.show() }) + it('should close modal when escape key is pressed with keyboard = true and backdrop is static', done => { + fixtureEl.innerHTML = '