Tooltip.updateTitleContent() and default options.innerSelector don't work well together
See original GitHub issueCodePen demo
https://codepen.io/anon/pen/WgRoZp?editors=1111
Steps to reproduce the problem
- Notice that all 4 tooltips start out with “default title”, as they should
- Hover over all 4 li elements
- Notice that only 1 tooltip has updated to “updated title”
What is the expected behavior?
All 4 should have updated.
What went wrong?
The code you use in your _updateTitleContent
(in index.js) function looks like:
_updateTitleContent(title) {
if(typeof this._tooltipNode === 'undefined') {
if(typeof this.options.title !== 'undefined') {
this.options.title = title;
}
return;
}
const titleNode = this._tooltipNode.parentNode.querySelector(this.options.innerSelector);
this._clearTitleContent(titleNode, this.options.html, this.reference.getAttribute('title') || this.options.title)
this._addTitleContent(this.reference, title, this.options.html, titleNode);
this.options.title = title;
this.popperInstance.update();
}
Why do you use .parentNode
? I think that should be removed. I would think the innerSelector
should be scoped so it selects descendants of the root tooltip element. But, by using parentNode, you select from the next parent up instead (in my case, parentNode is the ul
element). This causes the innerSelector to find too many matches, and an arbitrary single match is chosen by querySelector()
, causing only a single tooltip update.
Also, note that this is only a problem when you have more than 1 tooltip with the same parent, like I do with my ul and 4 li tooltip children.
Any other comments?
This is default config, and it’s broken. I don’t think telling people to choose a more distinct/selective innerSelector
would be a good solution to this. It would work, but pushes tedious bookkeeping onto the client to create unique ids and stick them into the innerSelector
.
Off topic - thanks for the great work on this lib!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top GitHub Comments
@FezVrasta It looks like this has been merged? If so, could you maybe release a new release on NPM with the fix?
I already released the fix