]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
prevent quick interactions from misplacing tooltips
authorRyan Berliner <ryan.berliner@gmail.com>
Sat, 6 Mar 2021 21:57:23 +0000 (23:57 +0200)
committerXhmikosR <xhmikosr@gmail.com>
Tue, 16 Mar 2021 05:48:50 +0000 (07:48 +0200)
js/src/tooltip.js
js/tests/unit/tooltip.spec.js

index e9f9bfff1b44fe23632666818326323be043c83a..857f72c8ad2c54531abe66637f0c73829248e4cb 100644 (file)
@@ -283,6 +283,10 @@ class Tooltip extends BaseComponent {
 
     EventHandler.trigger(this._element, this.constructor.Event.INSERTED)
 
+    if (this._popper) {
+      this._popper.destroy()
+    }
+
     this._popper = Popper.createPopper(this._element, tip, this._getPopperConfig(attachment))
 
     tip.classList.add(CLASS_NAME_SHOW)
@@ -650,7 +654,7 @@ class Tooltip extends BaseComponent {
     if (event) {
       context._activeTrigger[
         event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER
-      ] = false
+      ] = context._element.contains(event.relatedTarget)
     }
 
     if (context._isWithActiveTrigger()) {
index 41f73d6d8a7df925c04a4bd1c7d040c253cd4130..1cb301c151aa331443b57bcc360abff8eb1d113c 100644 (file)
@@ -708,8 +708,9 @@ describe('Tooltip', () => {
       tooltipEl.dispatchEvent(createEvent('mouseover'))
     })
 
-    it('should not hide tooltip if leave event occurs and enter event occurs during hide transition', done => {
-      fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip">'
+    it('should properly maintain tooltip state if leave event occurs and enter event occurs during hide transition', done => {
+      // Style this tooltip to give it plenty of room for popper to do what it wants
+      fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip" data-bs-placement="top" style="position:fixed;left:50%;top:50%;">Trigger</a>'
 
       const tooltipEl = fixtureEl.querySelector('a')
       const tooltip = new Tooltip(tooltipEl)
@@ -721,6 +722,7 @@ describe('Tooltip', () => {
 
       setTimeout(() => {
         expect(tooltip._popper).not.toBeNull()
+        expect(tooltip.getTipElement().getAttribute('data-popper-placement')).toBe('top')
         tooltipEl.dispatchEvent(createEvent('mouseout'))
 
         setTimeout(() => {
@@ -730,6 +732,7 @@ describe('Tooltip', () => {
 
         setTimeout(() => {
           expect(tooltip._popper).not.toBeNull()
+          expect(tooltip.getTipElement().getAttribute('data-popper-placement')).toBe('top')
           done()
         }, 200)
       }, 0)