menu icons broken, bad workaround
Categories
(Thunderbird :: Toolbars and Tabs, defect)
Tracking
(Not tracked)
People
(Reporter: axel.grude, Unassigned)
Details
Attachments
(1 file)
|
685.49 KB,
application/pdf
|
Details |
list-style-image not working for menu and menuitems.
This affects three of my Add-ons, but is especially problematic for my Add-on QuickFolders. This one shows menu structure which represent folder hierarchies. I used CSS list-style-image to style them both statically and dynamically (e.g. drag over), this is now broken. I see that the workaround is by injecting a static image attribute into the menuitem element. I have written some code that adjusts the menu items after creation (see below) but it's not a good solution, because status of folders (such as "has new mail") need additional overriding icons which is much easier done by css rules rather than script that affects an attribute.
For reference, please see: https://github.com/RealRaven2000/QuickFolders/issues/602
Also when a folder doesn't have a special / custom image it shows a placeholder square, so I had to overwrite with an empty svg square to avoid misalignment.
The new implementation of menus and menuitems basically seems to merge presentation layer and content by using html attributes.
Below the code that half patches the issue but cannot fix things like "unread", or ":hover" rules because it is a static solution:
// inside QuickFolders.Interface
patchMenuIcons: function(menupopup) {
const emptyIcon = `data:image/svg+xml;base64,${btoa(
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"></svg>'
)}`;
const applyImage = (item) => {
const listImg = window.getComputedStyle(item).getPropertyValue("list-style-image");
if (listImg && listImg !== "none") {
const match = listImg.match(/^url\(["']?(.*?)["']?\)$/);
if (match && match.length > 1) {
item.setAttribute("image", match[1]);
}
} else if (item.classList.contains("menu-iconic")) {
// preserve layout with empty SVG
item.setAttribute("image", emptyIcon);
}
};
menupopup.querySelectorAll("menuitem").forEach(applyImage);
menupopup.querySelectorAll("menu").forEach(applyImage);
},
attachPopupListener: function(menupopup) {
if (!menupopup) { return; }
menupopup.addEventListener("popupshowing", (_e) => {
QuickFolders.Interface.patchMenuIcons(menupopup);
// recursively attach to any nested menupopups
menupopup.querySelectorAll("menupopup").forEach((mp) => QuickFolders.Interface.attachPopupListener(mp));
});
},
can this be fixed in a different way or a CSS based solution found that can be overriden / fixed with additional CSS rules?
What other parts of menus are planned to be broken / removed? menus are a core mechanic for 2 of my 3 Add-ons and the API functions aren't sufficient for their functionality.
Comment 1•1 year ago
|
||
Because of an upstream change we needed to switch from list-style-image to content on the .menu-icon. To make it easier you can use a variable (--menuitem-icon) instead of list-style-image.
Instead of using
#YourMenuID {
list-style-icon: url("YourIcon");
}
you can use
#YourMenuID {
--menuitem-icon: url("YourIcon");
}
| Reporter | ||
Comment 2•1 year ago
|
||
(In reply to Richard Marti (:Paenglab) from comment #1)
Because of an upstream change we needed to switch from
list-style-imageto content on the .menu-icon. To make it easier you can use a variable (--menuitem-icon) instead oflist-style-image.
thanks, very good.
I tried your workaround on quickFilters, it appears to work very well there. We might revisit this item with John on the next dev call and reassign it to the Mozilla platform upstream.
Description
•