From: Giovanni Mendoza Date: Fri, 10 Jan 2020 09:06:12 +0000 (+0200) Subject: Backport #29886 X-Git-Tag: v4.5.0~126 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6daae47cc08342a7302b32f29654ac281298f498;p=thirdparty%2Fbootstrap.git Backport #29886 Close modal with keyboard=true & backdrop=static --- diff --git a/js/src/modal.js b/js/src/modal.js index ad925f6ff4..faaa8f1083 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/js/tests/unit/modal.js b/js/tests/unit/modal.js index b1ddc8512f..14cebe84f3 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -855,4 +855,53 @@ $(function () { backdrop: 'static' }) }) + + QUnit.test('should close modal when escape key is pressed with keyboard = true and backdrop is static', function (assert) { + assert.expect(1) + var done = assert.async() + var $modal = $('