}
_getTitle() {
- return this._resolvePossibleFunction(this._config.title) || this._element.getAttribute('title')
+ return this._config.title
}
// Private
}
_fixTitle() {
- const title = this._element.getAttribute('title')
+ const title = this._config.originalTitle
- if (title && !this._element.getAttribute('aria-label') && !this._element.textContent) {
+ if (!title) {
+ return
+ }
+
+ if (!this._element.getAttribute('aria-label') && !this._element.textContent) {
this._element.setAttribute('aria-label', title)
}
+
+ this._element.removeAttribute('title')
}
_enter() {
}
}
+ config.originalTitle = this._element.getAttribute('title') || ''
+ config.title = this._resolvePossibleFunction(config.title) || config.originalTitle
if (typeof config.title === 'number') {
config.title = config.title.toString()
}
expect(getPopperConfig).toHaveBeenCalled()
expect(popperConfig.placement).toEqual('left')
})
+
+ it('should use original title, if not "data-bs-title" is given', () => {
+ fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip"></a>'
+
+ const tooltipEl = fixtureEl.querySelector('a')
+ const tooltip = new Tooltip(tooltipEl)
+
+ expect(tooltip._config.title).toEqual('Another tooltip')
+ })
})
describe('enable', () => {
tooltip.show()
})
+
+ it('should remove `title` attribute if exists', done => {
+ fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip"></a>'
+
+ const tooltipEl = fixtureEl.querySelector('a')
+ const tooltip = new Tooltip(tooltipEl)
+
+ tooltipEl.addEventListener('shown.bs.tooltip', () => {
+ expect(tooltipEl.getAttribute('title')).toBeNull()
+ done()
+ })
+ tooltip.show()
+ })
})
describe('hide', () => {