Skip to content

Commit

Permalink
fix(reg): Re-set tooltip title, on disposal
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed Jul 22, 2022
1 parent 04b5d09 commit 3fca31b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions js/src/tooltip.js
Expand Up @@ -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()
}
Expand Down
19 changes: 19 additions & 0 deletions js/tests/unit/tooltip.spec.js
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 3fca31b

Please sign in to comment.