diff options
author | GeoSot <geo.sotis@gmail.com> | 2022-07-27 17:40:05 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-27 17:40:05 +0300 |
commit | dfae892801ffc194de6aec34d543d908db3dd8e1 (patch) | |
tree | d50188d942ae6fd7b050872b11fdcb544b2a0299 /js | |
parent | 44c9c8df8d8e5be84d5bea47f8ee110b64e86e62 (diff) |
Re-set tooltip title, on disposal (#36751)
fix(reg): Re-set tooltip title, on disposal
Diffstat (limited to 'js')
-rw-r--r-- | js/src/tooltip.js | 4 | ||||
-rw-r--r-- | js/tests/unit/tooltip.spec.js | 19 |
2 files changed, 23 insertions, 0 deletions
diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 54ec0367ed..2c5f03a293 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -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() } diff --git a/js/tests/unit/tooltip.spec.js b/js/tests/unit/tooltip.spec.js index c8ab068187..4330571b47 100644 --- a/js/tests/unit/tooltip.spec.js +++ b/js/tests/unit/tooltip.spec.js @@ -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', () => { |