-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
5.2.0: Popover - Unable to use getInstance
on .popover
element
#36837
Comments
I have a similar problem with the Carousel. My fix was using |
In both cases, you are initializing the popover Instance using the following script document.querySelectorAll('[data-bs-toggle="popover"]').forEach((popover) => {
new bootstrap.Popover(popover);
}); So, programmatically thinking if you want to use the methods of this instance, you have to keep it as a variable or to refer to it, using the same selector bootstrap.Popover.getInstance('[data-bs-toggle="popover"]'); Of course, you are right saying that you had found out a trick in where you could use the dynamic created element just to refer to the same instance, but as it was an intrusive and not documented way, I suppose you have to avoid it. const x= document.querySelector(`.popover`).getAttribute('id')
const initialElem = document.querySelector('[aria-describedby="'+ x +'"]') /cc @julien-deramond any different opinion on this? |
I think updating my code to use the documented method that you've suggested makes the most sense. Is it worth updating the migration guide to mention the removal of the undocumented way? |
I think is controversial, to document (mention) a change on an undocumented way 😉 |
Hi @GeoSot, should I use the way you described to migrate my Bootstrap v5.1 code to Bootstrap v5.2 code? I need to close all open tooltips and popovers. This is my current code: $('.tooltip').tooltip('hide'); // Close all open tooltips.
$('.popover').popover('hide'); // Close all open popovers. |
Something like ??? document.querySelectorAll('[data-bs-toggle="popover"][aria-describedby]').forEach((popover) => {
bootstrap.Popover.getOrCreateInstance(popover).hide();
}); (same for tooltip) |
That's what I thought, thank you @GeoSot! |
Prerequisites
Describe the issue
Regression from
v5.1.3
. Can no longer get the Popover instance from the.popover
element itself.e.g.
it now only works when using it on the trigger, e.g.
Reduced test cases
v5.2.0: https://stackblitz.com/edit/h7ep9y?file=index.html,index.js
v5.1.3: https://stackblitz.com/edit/h7ep9y-vtddun?file=index.html
What operating system(s) are you seeing the problem on?
Linux
What browser(s) are you seeing the problem on?
Chrome
What version of Bootstrap are you using?
v5.2.0
The text was updated successfully, but these errors were encountered: