Tooltip customClass function does not update if trigger's class changes while visible #41765
Replies: 1 comment 1 reply
|
By design, the customClass option in Bootstrap is only evaluated when the tooltip is created/shown, not continuously while it’s visible. That’s why you’re seeing the “stale” state — the function isn’t re-invoked just because your trigger element’s classes changed after the tooltip was already open. Why this happens On mouseenter/focus, Bootstrap calls your customClass function and applies the result to the tooltip element. Once rendered, the tooltip’s DOM is independent — it won’t automatically re-sync with changes to the trigger element unless you explicitly tell it to. Options to keep it in sync Force a refresh tooltipInstance.update(); or hide/show it again: tooltipInstance.hide(); That re-evaluates customClass(). Use a MutationObserver const observer = new MutationObserver(() => tooltipInstance.update()); Manual toggling |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I'm using the tooltip's customClass option as a function to dynamically style the tooltip based on the trigger element's class. I've found a potential race condition when the trigger's classes are updated frequently.
My initialization code looks like this:
The Bug / Race Condition:
Expected behavior: The tooltip's style should reflect the current state of the trigger element.
Question: Is this the intended behavior, or should the tooltip instance react to class changes on its trigger element while it is visible?
Thank you!
All reactions