Skip to content

Commit b92a320

Browse files
ky-lernikk15
authored andcommitted
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
1 parent 00b6812 commit b92a320

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

browser/base/content/main-popupset.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ document.addEventListener(
495495
ToolbarContextMenu.updateDownloadsAlwaysOpenPanel(event.target);
496496
ToolbarContextMenu.updateExtensionsButtonContextMenu(event.target);
497497
ToolbarContextMenu.updateExtension(event.target);
498+
// hideLeadingSeparatorIfNeeded must be called last after updating the menu items above,
499+
// as they may change which items are visible.
500+
ToolbarContextMenu.hideLeadingSeparatorIfNeeded(event.target);
498501
break;
499502
case "pageActionContextMenu":
500503
BrowserPageActions.onContextMenuShowing(event, event.target);

browser/components/customizableui/ToolbarContextMenu.sys.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,4 +553,30 @@ export var ToolbarContextMenu = {
553553
let id = this._getExtensionId(popup);
554554
await BrowserAddonUI.manageAddon(id, "browserAction");
555555
},
556+
557+
/**
558+
* Hides the first visible menu separator if it would appear at the top of the
559+
* toolbar context menu (i.e., when all preceding menu items are hidden). This
560+
* prevents a separator from appearing at the top of the menu with no items above it.
561+
*
562+
* Fix for Bug 1955241.
563+
*
564+
* @param {Element} popup
565+
* The toolbar-context-menu element for a window.
566+
*/
567+
hideLeadingSeparatorIfNeeded(popup) {
568+
// Find the first non-hidden element in the menu
569+
let firstVisibleElement = popup.firstElementChild;
570+
while (firstVisibleElement && firstVisibleElement.hidden) {
571+
firstVisibleElement = firstVisibleElement.nextElementSibling;
572+
}
573+
574+
// If the first visible element is a separator, hide it
575+
if (
576+
firstVisibleElement &&
577+
firstVisibleElement.localName === "menuseparator"
578+
) {
579+
firstVisibleElement.hidden = true;
580+
}
581+
},
556582
};

0 commit comments

Comments
 (0)