diff --git a/js/src/modal.js b/js/src/modal.js index fb787208d8..1ea630c415 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -113,7 +113,7 @@ const Modal = (() => { } show(relatedTarget) { - if (this._isTransitioning) { + if (this._isTransitioning || this._isShown) { return } diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index e026cd7f14..e081a6dc25 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -673,4 +673,20 @@ $(function () { $toggleBtn.trigger('click') setTimeout(done, 500) }) + + QUnit.test('should not try to open a modal which is already visible', function (assert) { + assert.expect(1) + var done = assert.async() + var count = 0 + + $('
').on('shown.bs.modal', function () { + count++ + }).on('hidden.bs.modal', function () { + assert.strictEqual(count, 1, 'show() runs only once') + done() + }) + .bootstrapModal('show') + .bootstrapModal('show') + .bootstrapModal('hide') + }) })