Skip to content

Commit f7a4b39

Browse files
committed
handle detached tooltip when we try to hide a modal
1 parent e0d1f3f commit f7a4b39

File tree

2 files changed

+67
-5
lines changed

2 files changed

+67
-5
lines changed

js/src/tooltip.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,17 @@ class Tooltip {
486486
(event) => this._leave(event)
487487
)
488488
}
489-
490-
$(this.element).closest('.modal').on(
491-
'hide.bs.modal',
492-
() => this.hide()
493-
)
494489
})
495490

491+
$(this.element).closest('.modal').on(
492+
'hide.bs.modal',
493+
() => {
494+
if (this.element) {
495+
this.hide()
496+
}
497+
}
498+
)
499+
496500
if (this.config.selector) {
497501
this.config = {
498502
...this.config,

js/tests/unit/tooltip.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,44 @@ $(function () {
862862
.modal('show')
863863
})
864864

865+
QUnit.test('should allow to close modal if the tooltip element is detached', function (assert) {
866+
assert.expect(1)
867+
var done = assert.async()
868+
var templateHTML = [
869+
'<div id="modal-test" class="modal">',
870+
' <div class="modal-dialog" role="document">',
871+
' <div class="modal-content">',
872+
' <div class="modal-body">',
873+
' <a id="tooltipTest" href="#" data-toggle="tooltip" title="Some tooltip text!">Tooltip</a>',
874+
' </div>',
875+
' </div>',
876+
' </div>',
877+
'</div>'
878+
].join('')
879+
880+
$(templateHTML).appendTo('#qunit-fixture')
881+
var $tooltip = $('#tooltipTest')
882+
var $modal = $('#modal-test')
883+
884+
$tooltip.on('shown.bs.tooltip', function () {
885+
$tooltip.detach()
886+
$tooltip.bootstrapTooltip('dispose')
887+
$modal.modal('hide')
888+
})
889+
890+
$modal.on('shown.bs.modal', function () {
891+
$tooltip.bootstrapTooltip({
892+
trigger: 'manuel'
893+
})
894+
.bootstrapTooltip('show')
895+
})
896+
.on('hidden.bs.modal', function () {
897+
assert.ok(true, 'modal hidden')
898+
done()
899+
})
900+
.modal('show')
901+
})
902+
865903
QUnit.test('should reset tip classes when hidden event triggered', function (assert) {
866904
assert.expect(2)
867905
var done = assert.async()
@@ -966,4 +1004,24 @@ $(function () {
9661004

9671005
assert.ok(tooltip.tip === $tipTest[0])
9681006
})
1007+
1008+
QUnit.test('should toggle enabled', function (assert) {
1009+
assert.expect(3)
1010+
1011+
var $tooltip = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
1012+
.appendTo('#qunit-fixture')
1013+
.bootstrapTooltip()
1014+
1015+
var tooltip = $tooltip.data('bs.tooltip')
1016+
1017+
assert.strictEqual(tooltip._isEnabled, true)
1018+
1019+
tooltip.toggleEnabled()
1020+
1021+
assert.strictEqual(tooltip._isEnabled, false)
1022+
1023+
tooltip.toggleEnabled()
1024+
1025+
assert.strictEqual(tooltip._isEnabled, true)
1026+
})
9691027
})

0 commit comments

Comments
 (0)