]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
fix(tooltip): get tip on placement change
authorJohann-S <johann.servoire@gmail.com>
Mon, 30 Apr 2018 08:49:43 +0000 (10:49 +0200)
committerJohann-S <johann.servoire@gmail.com>
Mon, 25 Jun 2018 14:54:14 +0000 (16:54 +0200)
js/src/tooltip.js
js/tests/unit/tooltip.js

index 56c1aa0d1545bba0326b46f12dcaccba04299d8d..c66e48385dc89ed42f49c25ec00500d09d537867 100644 (file)
@@ -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() {
index 670e6d0c2e503be872eefb1b8f91af62bdf30eed..9cf3068a3636ef9b958db066ec198066f58a5023 100644 (file)
@@ -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 = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
+      .appendTo('#qunit-fixture')
+      .bootstrapTooltip()
+
+    var $tipTest = $('<div class="bs-tooltip" />')
+      .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])
+  })
 })