]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Re-set tooltip title, on disposal (#36751)
authorGeoSot <geo.sotis@gmail.com>
Wed, 27 Jul 2022 14:40:05 +0000 (17:40 +0300)
committerGitHub <noreply@github.com>
Wed, 27 Jul 2022 14:40:05 +0000 (17:40 +0300)
fix(reg): Re-set tooltip title, on disposal

js/src/tooltip.js
js/tests/unit/tooltip.spec.js

index 54ec0367ed437f4b71375c068e2857aa443bc97c..2c5f03a29340d066267105899e9e4cd647717e1b 100644 (file)
@@ -185,6 +185,10 @@ class Tooltip extends BaseComponent {
       this.tip.remove()
     }
 
+    if (this._config.originalTitle) {
+      this._element.setAttribute('title', this._config.originalTitle)
+    }
+
     this._disposePopper()
     super.dispose()
   }
index c8ab068187e91de64ae8bef3117eee90884a5ef5..4330571b476ee15592a7bcdd0dc988e082505780 100644 (file)
@@ -419,6 +419,25 @@ describe('Tooltip', () => {
         tooltip.show()
       })
     })
+
+    it('should destroy a tooltip and reset it\'s initial title', () => {
+      fixtureEl.innerHTML = [
+        '<span id="tooltipWithTitle" rel="tooltip" title="tooltipTitle"></span>',
+        '<span id="tooltipWithoutTitle" rel="tooltip" data-bs-title="tooltipTitle"></span>'
+      ].join('')
+
+      const tooltipWithTitleEl = fixtureEl.querySelector('#tooltipWithTitle')
+      const tooltip = new Tooltip('#tooltipWithTitle')
+      expect(tooltipWithTitleEl.getAttribute('title')).toBeNull()
+      tooltip.dispose()
+      expect(tooltipWithTitleEl.getAttribute('title')).toBe('tooltipTitle')
+
+      const tooltipWithoutTitleEl = fixtureEl.querySelector('#tooltipWithoutTitle')
+      const tooltip2 = new Tooltip('#tooltipWithTitle')
+      expect(tooltipWithoutTitleEl.getAttribute('title')).toBeNull()
+      tooltip2.dispose()
+      expect(tooltipWithoutTitleEl.getAttribute('title')).toBeNull()
+    })
   })
 
   describe('show', () => {