From 398cb073332899a1af4b7bc31a232fd1a8a2eda6 Mon Sep 17 00:00:00 2001 From: Giovanni Mendoza Date: Fri, 10 Jan 2020 03:06:12 -0600 Subject: [PATCH] NEEDS TESTS Close modal with keyboard=true & backdrop=static (#29986) * Close modal with keyboard=true & backdrop=static --- js/src/modal.js | 7 +++++-- site/docs/4.4/components/modal.md | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/js/src/modal.js b/js/src/modal.js index ad925f6ff429..faaa8f108386 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -325,9 +325,12 @@ class Modal { } _setEscapeEvent() { - if (this._isShown && this._config.keyboard) { + if (this._isShown) { $(this._element).on(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/site/docs/4.4/components/modal.md b/site/docs/4.4/components/modal.md index 6bd573d7a7c5..aebfd9e10063 100644 --- a/site/docs/4.4/components/modal.md +++ b/site/docs/4.4/components/modal.md @@ -139,7 +139,7 @@ Toggle a working modal demo by clicking the button below. It will slide down and When backdrop is set to static, the modal will not close when clicking outside it. Click the button below to try it. -