From 954a0b1e6a206e4df910d4799d013f4388a2ef40 Mon Sep 17 00:00:00 2001 From: Giovanni Mendoza Date: Fri, 10 Jan 2020 03:06:12 -0600 Subject: [PATCH] Close modal with keyboard=true & backdrop=static (#29986) * Close modal with keyboard=true & backdrop=static --- js/src/modal.js | 7 ++- js/tests/unit/modal.spec.js | 58 +++++++++++++++++++++++ site/content/docs/4.3/components/modal.md | 8 ++-- 3 files changed, 67 insertions(+), 6 deletions(-) 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 = '