Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/8024_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix modebar hover colors not updating after `color` or `activecolor` changes [[#8024](https://github.com/plotly/plotly.js/pull/8024)]
13 changes: 10 additions & 3 deletions src/lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,29 @@ function setStyleOnHover(selector, activeSelector, childSelector, activeStyle, i
element = document;
}
element.querySelectorAll(selector).forEach(function(el) {
el._hoverStyle = {
activeStyleParts: activeStyleParts,
inactiveStyleParts: inactiveStyleParts
};

if(!el.getAttribute(eventAddedAttrName)) {
// Emulate ":hover" CSS style using JS event handlers to set the
// style in a strict CSP-compliant manner.
el.addEventListener('mouseenter', function() {
var hoverStyle = this._hoverStyle;
var childEl = this.querySelector(childSelector);
if(childEl) {
childEl.style[activeStyleParts[0]] = activeStyleParts[1];
childEl.style[hoverStyle.activeStyleParts[0]] = hoverStyle.activeStyleParts[1];
}
});
el.addEventListener('mouseleave', function() {
var hoverStyle = this._hoverStyle;
var childEl = this.querySelector(childSelector);
if(childEl) {
if(activeSelector && this.matches(activeSelector)) {
childEl.style[activeStyleParts[0]] = activeStyleParts[1];
childEl.style[hoverStyle.activeStyleParts[0]] = hoverStyle.activeStyleParts[1];
} else {
childEl.style[inactiveStyleParts[0]] = inactiveStyleParts[1];
childEl.style[hoverStyle.inactiveStyleParts[0]] = hoverStyle.inactiveStyleParts[1];
}
}
});
Expand Down
Loading