0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01:00

Handle non-empty whitespace textContent in Tooltip trigger (#36588)

This commit is contained in:
Nathan Walters 2022-07-05 22:15:50 -07:00 committed by GitHub
parent 7d0b224df4
commit 3f324eed02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -518,7 +518,7 @@ class Tooltip extends BaseComponent {
return return
} }
if (!this._element.getAttribute('aria-label') && !this._element.textContent) { if (!this._element.getAttribute('aria-label') && !this._element.textContent.trim()) {
this._element.setAttribute('aria-label', title) this._element.setAttribute('aria-label', title)
} }

View File

@ -1358,6 +1358,25 @@ describe('Tooltip', () => {
}) })
}) })
it('should add the aria-label attribute when element text content is a whitespace string', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="A tooltip"><span> </span></a>'
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)
tooltipEl.addEventListener('shown.bs.tooltip', () => {
const tooltipShown = document.querySelector('.tooltip')
expect(tooltipShown).not.toBeNull()
expect(tooltipEl.getAttribute('aria-label')).toEqual('A tooltip')
resolve()
})
tooltip.show()
})
})
it('should not add the aria-label attribute if the attribute already exists', () => { it('should not add the aria-label attribute if the attribute already exists', () => {
return new Promise(resolve => { return new Promise(resolve => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip" aria-label="Different label" title="Another tooltip"></a>' fixtureEl.innerHTML = '<a href="#" rel="tooltip" aria-label="Different label" title="Another tooltip"></a>'