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:
parent
7d0b224df4
commit
3f324eed02
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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>'
|
||||||
|
Loading…
Reference in New Issue
Block a user