commit b92a320b12738c91fb97028e0aaf0bf2c17dae89
parent 00b68125d6793183e71d3960a96536a70e036fa3
Author: Kyler Riggs <100742516+ky-ler@users.noreply.github.com>
Date: Wed, 1 Oct 2025 13:06:39 +0000
Bug 1955241 - Fix separator appearing at top of toolbar context menu with no items above it. r=nsharpley
Differential Revision: https://phabricator.services.mozilla.com/D266705
Diffstat:
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/browser/base/content/main-popupset.js b/browser/base/content/main-popupset.js
@@ -495,6 +495,9 @@ document.addEventListener(
ToolbarContextMenu.updateDownloadsAlwaysOpenPanel(event.target);
ToolbarContextMenu.updateExtensionsButtonContextMenu(event.target);
ToolbarContextMenu.updateExtension(event.target);
+ // hideLeadingSeparatorIfNeeded must be called last after updating the menu items above,
+ // as they may change which items are visible.
+ ToolbarContextMenu.hideLeadingSeparatorIfNeeded(event.target);
break;
case "pageActionContextMenu":
BrowserPageActions.onContextMenuShowing(event, event.target);
diff --git a/browser/components/customizableui/ToolbarContextMenu.sys.mjs b/browser/components/customizableui/ToolbarContextMenu.sys.mjs
@@ -553,4 +553,30 @@ export var ToolbarContextMenu = {
let id = this._getExtensionId(popup);
await BrowserAddonUI.manageAddon(id, "browserAction");
},
+
+ /**
+ * Hides the first visible menu separator if it would appear at the top of the
+ * toolbar context menu (i.e., when all preceding menu items are hidden). This
+ * prevents a separator from appearing at the top of the menu with no items above it.
+ *
+ * Fix for Bug 1955241.
+ *
+ * @param {Element} popup
+ * The toolbar-context-menu element for a window.
+ */
+ hideLeadingSeparatorIfNeeded(popup) {
+ // Find the first non-hidden element in the menu
+ let firstVisibleElement = popup.firstElementChild;
+ while (firstVisibleElement && firstVisibleElement.hidden) {
+ firstVisibleElement = firstVisibleElement.nextElementSibling;
+ }
+
+ // If the first visible element is a separator, hide it
+ if (
+ firstVisibleElement &&
+ firstVisibleElement.localName === "menuseparator"
+ ) {
+ firstVisibleElement.hidden = true;
+ }
+ },
};