Skip to content

Fix stale modebar hover colors after style updates - #8024

Open
Lexachoc wants to merge 2 commits into
plotly:mainfrom
Lexachoc:fix-modebar-hover
Open

Fix stale modebar hover colors after style updates#8024
Lexachoc wants to merge 2 commits into
plotly:mainfrom
Lexachoc:fix-modebar-hover

Conversation

@Lexachoc

@Lexachoc Lexachoc commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Closes #8023

This PR fixes modebar hover colors retaining the initial color and activecolor values after they are updated, for example when switching between light and dark themes.

setStyleOnHover() attaches the mouseenter and mouseleave listeners only once. As a result, both listeners therefore kept the activeStyleParts and inactiveStyleParts values from the initial call.

plotly.js/src/lib/dom.js

Lines 104 to 134 in c5ad356

function setStyleOnHover(selector, activeSelector, childSelector, activeStyle, inactiveStyle, element) {
var activeStyleParts = activeStyle.split(':');
var inactiveStyleParts = inactiveStyle.split(':');
var eventAddedAttrName = 'data-btn-style-event-added';
if (!element) {
element = document;
}
element.querySelectorAll(selector).forEach(function(el) {
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 childEl = this.querySelector(childSelector);
if(childEl) {
childEl.style[activeStyleParts[0]] = activeStyleParts[1];
}
});
el.addEventListener('mouseleave', function() {
var childEl = this.querySelector(childSelector);
if(childEl) {
if(activeSelector && this.matches(activeSelector)) {
childEl.style[activeStyleParts[0]] = activeStyleParts[1];
} else {
childEl.style[inactiveStyleParts[0]] = inactiveStyleParts[1];
}
}
});
el.setAttribute(eventAddedAttrName, true);
}
});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Modebar hover colors remain stale after color/activecolor updates when switching themes

1 participant