Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle detached tooltip when we try to hide a modal #27578

Merged
merged 2 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
58 changes: 58 additions & 0 deletions js/tests/unit/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
'<div id="modal-test" class="modal">',
' <div class="modal-dialog" role="document">',
' <div class="modal-content">',
' <div class="modal-body">',
' <a id="tooltipTest" href="#" data-toggle="tooltip" title="Some tooltip text!">Tooltip</a>',
' </div>',
' </div>',
' </div>',
'</div>'
].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()
Expand Down Expand Up @@ -966,4 +1004,24 @@ $(function () {

assert.ok(tooltip.tip === $tipTest[0])
})

QUnit.test('should toggle enabled', function (assert) {
assert.expect(3)

var $tooltip = $('<a href="#" rel="tooltip" data-trigger="click" title="Another 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)
})
})