From 8e9ad83309210b8e175399c44579f3c14d1c7fc2 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Fri, 2 Nov 2018 10:24:35 +0100 Subject: [PATCH] handle detached tooltip when we try to hide a modal --- js/src/tooltip.js | 14 ++++++---- js/tests/unit/tooltip.js | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 3d3130bb5b10..cf8b8e118681 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -486,13 +486,17 @@ class Tooltip { (event) => this._leave(event) ) } - - $(this.element).closest('.modal').on( - 'hide.bs.modal', - () => this.hide() - ) }) + $(this.element).closest('.modal').on( + 'hide.bs.modal', + () => { + if (this.element) { + this.hide() + } + } + ) + if (this.config.selector) { this.config = { ...this.config, diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 9cf3068a3636..7652d4cf869c 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -862,6 +862,44 @@ $(function () { .modal('show') }) + QUnit.test('should allow to close modal if the tooltip element is detached', function (assert) { + assert.expect(1) + var done = assert.async() + var templateHTML = [ + '' + ].join('') + + $(templateHTML).appendTo('#qunit-fixture') + var $tooltip = $('#tooltipTest') + var $modal = $('#modal-test') + + $tooltip.on('shown.bs.tooltip', function () { + $tooltip.detach() + $tooltip.bootstrapTooltip('dispose') + $modal.modal('hide') + }) + + $modal.on('shown.bs.modal', function () { + $tooltip.bootstrapTooltip({ + trigger: 'manuel' + }) + .bootstrapTooltip('show') + }) + .on('hidden.bs.modal', function () { + assert.ok(true, 'modal hidden') + done() + }) + .modal('show') + }) + QUnit.test('should reset tip classes when hidden event triggered', function (assert) { assert.expect(2) var done = assert.async() @@ -966,4 +1004,24 @@ $(function () { assert.ok(tooltip.tip === $tipTest[0]) }) + + QUnit.test('should toggle enabled', function (assert) { + assert.expect(3) + + var $tooltip = $('') + .appendTo('#qunit-fixture') + .bootstrapTooltip() + + var tooltip = $tooltip.data('bs.tooltip') + + assert.strictEqual(tooltip._isEnabled, true) + + tooltip.toggleEnabled() + + assert.strictEqual(tooltip._isEnabled, false) + + tooltip.toggleEnabled() + + assert.strictEqual(tooltip._isEnabled, true) + }) })