Skip to content

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

Description

@DKhalil

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

Activity

  1. added
    jsJavaScript or TypeScript sources and plugins
    v5v5, the v5-dev branch
    on Sep 26, 2022
  2. julien-deramond commented on Sep 26, 2022

    @julien-deramond
    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?

  3. DKhalil commented on Sep 26, 2022

    @DKhalil
    Author

    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.

  4. julien-deramond commented on Sep 26, 2022

    @julien-deramond
    Member

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

  5. removed
    awaiting-replyWaiting on the author; an issue closes after 14 days without reply
    on Sep 26, 2022
  6. GeoSot commented on Sep 26, 2022

    @GeoSot
    Member

    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

  7. DKhalil commented on Sep 27, 2022

    @DKhalil
    Author

    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

  8. monsterRocky commented on Oct 2, 2022

    @monsterRocky
  9. dragonofmercy commented on Nov 14, 2022

    @dragonofmercy

    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

  10. added
    bugSomething does not work as documented
    confirmedReproduced with a reduced test case
    v6v6, the main branch
    has-prAn open pull request addresses it
    on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething does not work as documentedconfirmedReproduced with a reduced test casehas-prAn open pull request addresses itjsJavaScript or TypeScript sources and pluginsv5v5, the v5-dev branchv6v6, the main branch

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions