Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions js/src/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,14 @@ class Tooltip extends BaseComponent {
}
}

if (this._element.getAttribute('data-bs-title') !== null) {
dataAttributes.title = this._element.getAttribute('data-bs-title')
}

if (this._element.getAttribute('data-bs-content') !== null) {
dataAttributes.content = this._element.getAttribute('data-bs-content')
}

config = {
...dataAttributes,
...(typeof config === 'object' && config ? config : {})
Expand Down Expand Up @@ -961,11 +969,15 @@ class Tooltip extends BaseComponent {
// Coerce number/boolean title and content to strings. `data-bs-title="true"`
// / `data-bs-content="false"` are auto-converted to booleans by the data-API,
// which would otherwise fail the (null|string|element|function) type check.
if (typeof config.title === 'number' || typeof config.title === 'boolean') {
if (config.title === null) {
config.title = ''
} else if (typeof config.title === 'number' || typeof config.title === 'boolean') {
config.title = config.title.toString()
}

if (typeof config.content === 'number' || typeof config.content === 'boolean') {
if (config.content === null) {
config.content = ''
} else if (typeof config.content === 'number' || typeof config.content === 'boolean') {
config.content = config.content.toString()
}

Expand Down
10 changes: 10 additions & 0 deletions js/tests/unit/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ describe('Tooltip', () => {
expect(tooltip._config.content).toEqual('false')
})

it('should preserve raw strings without reformatting numbers or throwing on empty title/content', () => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip" data-bs-title="9.90" data-bs-content=""></a>'

const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)

expect(tooltip._config.title).toEqual('9.90')
expect(tooltip._config.content).toEqual('')
})

it('should enable selector delegation', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = '<div></div>'
Expand Down