From e57a2f244ba8446fffe71847e6a58b18f7b2d541 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Mon, 30 Apr 2018 10:49:43 +0200 Subject: [PATCH] fix(tooltip): get tip on placement change --- js/src/tooltip.js | 6 ++++-- js/tests/unit/tooltip.js | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 56c1aa0d15..c66e48385d 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -660,9 +660,11 @@ const Tooltip = (($) => { } } - _handlePopperPlacementChange(data) { + _handlePopperPlacementChange(popperData) { + const popperInstance = popperData.instance + this.tip = popperInstance.popper this._cleanTipClass() - this.addAttachmentClass(this._getAttachment(data.placement)) + this.addAttachmentClass(this._getAttachment(popperData.placement)) } _fixTransition() { diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 670e6d0c2e..9cf3068a36 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -943,4 +943,27 @@ $(function () { assert.ok(tooltip._popper === null) }) + + QUnit.test('should use Popper.js to get the tip on placement change', function (assert) { + assert.expect(1) + + var $tooltip = $('') + .appendTo('#qunit-fixture') + .bootstrapTooltip() + + var $tipTest = $('
') + .appendTo('#qunit-fixture') + + var tooltip = $tooltip.data('bs.tooltip') + tooltip.tip = null + + tooltip._handlePopperPlacementChange({ + instance: { + popper: $tipTest[0] + }, + placement: 'auto' + }) + + assert.ok(tooltip.tip === $tipTest[0]) + }) })