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 = $('