diff --git a/js/src/modal.js b/js/src/modal.js index 704b022472..0004fe8bbe 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -196,9 +196,17 @@ class Modal { } dispose() { - $.removeData(this._element, DATA_KEY) + [window, this._element, this._dialog] + .forEach((htmlElement) => $(htmlElement).off(EVENT_KEY)) - $(window, document, this._element, this._backdrop).off(EVENT_KEY) + /** + * `document` has 2 events `Event.FOCUSIN` and `Event.CLICK_DATA_API` + * Do not move `document` in `htmlElements` array + * It will remove `Event.CLICK_DATA_API` event that should remain + */ + $(document).off(Event.FOCUSIN) + + $.removeData(this._element, DATA_KEY) this._config = null this._element = null diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index 7c8299109e..4c857105b8 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -697,4 +697,37 @@ $(function () { beginTimestamp = Date.now() }) + + QUnit.test('should dispose modal', function (assert) { + assert.expect(3) + var done = assert.async() + + var $modal = $([ + '