Hide selected item background when mouse leaves menu (#4623)
Some checks are pending
CI / Build, Upload, Test (push) Waiting to run

This commit is contained in:
Abe Jellinek 2024-09-01 04:13:48 -04:00 committed by GitHub
parent 181196149a
commit 474b0eb0d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -170,6 +170,37 @@ Services.scriptloader.loadSubScript('chrome://zotero/content/elements/itemPaneSe
// Disable the fading animation when the popup is closed by clicking
this.setAttribute("animate", "false-once");
});
// The _moz-menuactive attribute isn't removed from menulist items
// when the mouse leaves the menu. On menulists only, replace the attribute
// with a marker that will be used to restore the _moz-menuactive attribute
// when the mouse reenters the menu.
// (We need to manually restore _moz-menuactive because it won't automatically
// be re-added if the mouse exits the menu and then enters again on the same
// item.)
this.addEventListener("mouseleave", () => {
if (this.parentElement?.localName !== "menulist") {
return;
}
// Only apply to top-level <menuitems>, not sub-<menu>s or nested <menuitem>s,
// because those already have the right behavior
let activeChild = this.querySelector(":scope > menuitem[_moz-menuactive='true']");
if (activeChild) {
activeChild.removeAttribute("_moz-menuactive");
activeChild.dataset.activeBeforeMouseleave = "true";
}
});
this.addEventListener("mouseover", (event) => {
if (this.parentElement?.localName !== "menulist") {
return;
}
let { target } = event;
if (target.parentElement === this && target.dataset.activeBeforeMouseleave) {
target.setAttribute("_moz-menuactive", "true");
delete target.dataset.activeBeforeMouseleave;
}
});
}
originalEnsureInitialized.apply(this);
};