Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-set tooltip title on disposal #36751

Merged
merged 3 commits into from Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>'
GeoSot marked this conversation as resolved.
Show resolved Hide resolved
].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