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

Fix popover doesn't show if its content or title is set dynamically after init #40851

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
3 changes: 1 addition & 2 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,13 @@ class Tooltip extends BaseComponent {
throw new Error('Please use show on visible elements')
}

if (!(this._isWithContent() && this._isEnabled)) {
if (!((this._isWithContent() || this._newContent !== null) && this._isEnabled)) {
return
}

const showEvent = EventHandler.trigger(this._element, this.constructor.eventName(EVENT_SHOW))
const shadowRoot = findShadowRoot(this._element)
const isInTheDom = (shadowRoot || this._element.ownerDocument.documentElement).contains(this._element)

if (showEvent.defaultPrevented || !isInTheDom) {
return
}
Expand Down
20 changes: 20 additions & 0 deletions js/tests/unit/popover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ describe('Popover', () => {
})

describe('show', () => {
it('should show a popover with no content after setContent', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = '<a href="#">BS twitter</a>'

const popoverEl = fixtureEl.querySelector('a')
const popover = Popover.getOrCreateInstance(popoverEl)

popoverEl.addEventListener('shown.bs.popover', () => {
expect(document.querySelector('.popover')).not.toBeNull()
resolve()
})

popover.setContent({
'.popover-body': 'some content'
})

popover.show()
})
})

it('should toggle a popover after show', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = '<a href="#" title="Popover" data-bs-content="https://twitter.com/getbootstrap">BS twitter</a>'
Expand Down
Loading