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

Popover setContent closes Popover after being opened with .show() or on hover #37206

Open
3 tasks done
DKhalil opened this issue Sep 26, 2022 · 7 comments
Open
3 tasks done
Labels

Comments

@DKhalil
Copy link

DKhalil commented Sep 26, 2022

Prerequisites

Describe the issue

Whenever I update the content of a popover (e.g. after loading the final content from an API) after having opened the Popover manually it closes again after calling setContent().

Reduced test cases

https://codepen.io/dkhalil/pen/eYreLbQ

What operating system(s) are you seeing the problem on?

Windows

What browser(s) are you seeing the problem on?

Chrome

What version of Bootstrap are you using?

v5.2.1

@julien-deramond
Copy link
Member

setContent() destroys the popper and then shows it:

bootstrap/js/src/tooltip.js

Lines 338 to 344 in 24f6e27

setContent(content) {
this._newContent = content
if (this._isShown()) {
this._disposePopper()
this.show()
}
}

I'm not sure it is possible to set a new content without disposing the popper when it is already shown.
@GeoSot thoughts?

But I'm curious. A popover is linked to an action, so what would be the use case where we have an opened popover which must be updated on the fly? In other words, why the popover is not shown with the right content in the first place?

@DKhalil
Copy link
Author

DKhalil commented Sep 26, 2022

Well, it's only shown if it was already open: if (this._isShown()) {
As I mentioned in the issue, in my use case it's because I want to asynchronously load in the content when the popover is opened, first displaying a loading animation then the content.

@julien-deramond
Copy link
Member

Yep OK. Read it too quickly. I see your point.

@GeoSot
Copy link
Member

GeoSot commented Sep 26, 2022

quick answer: During the first effort, popper wasn't able to render the changed content properly. So the only way was to close it and re-render it

@DKhalil
Copy link
Author

DKhalil commented Sep 27, 2022

Okay, so I replaced setContent with this in my code now:

instance.tip.querySelector('.popover-body').innerHTML = 'New Content'
instance.update()

That could be a fix in bootstrap as well, but I don't have the time right now to delve deep enough into the codebase to do a proper PR

@monsterRocky

This comment was marked as spam.

@dragonofmercy
Copy link

But I'm curious. A popover is linked to an action, so what would be the use case where we have an opened popover which must be updated on the fly? In other words, why the popover is not shown with the right content in the first place?

A simple example: show the value of the input range
Cd9SK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants