Bug 1269497 - Add 'visible' support to MenuItem API;r=jdescottes
MozReview-Commit-ID: 3tmhissxNYi
--- a/devtools/client/framework/menu-item.js
+++ b/devtools/client/framework/menu-item.js
@@ -39,20 +39,22 @@ function MenuItem({
accesskey = null,
checked = false,
click = () => {},
disabled = false,
label = "",
id = null,
submenu = null,
type = "normal",
+ visible = true,
} = { }) {
this.accesskey = accesskey;
this.checked = checked;
this.click = click;
this.disabled = disabled;
this.id = id;
this.label = label;
this.submenu = submenu;
this.type = type;
+ this.visible = visible;
}
module.exports = MenuItem;
--- a/devtools/client/framework/menu.js
+++ b/devtools/client/framework/menu.js
@@ -87,16 +87,20 @@ Menu.prototype.popup = function(screenX,
doc.querySelector("popupset").appendChild(popup);
popup.openPopupAtScreen(screenX, screenY, true);
};
Menu.prototype._createMenuItems = function(parent) {
let doc = parent.ownerDocument;
this.menuitems.forEach(item => {
+ if (!item.visible) {
+ return;
+ }
+
if (item.submenu) {
let menupopup = doc.createElement("menupopup");
item.submenu._createMenuItems(menupopup);
let menu = doc.createElement("menu");
menu.appendChild(menupopup);
menu.setAttribute("label", item.label);
parent.appendChild(menu);
--- a/devtools/client/framework/test/browser_menu_api.js
+++ b/devtools/client/framework/test/browser_menu_api.js
@@ -66,16 +66,22 @@ function* testMenuPopup(toolbox) {
disabled: true,
}),
];
for (let item of MENU_ITEMS) {
menu.append(item);
}
+ // Append an invisible MenuItem, which shouldn't show up in the DOM
+ menu.append(new MenuItem({
+ label: "Invisible",
+ visible: false,
+ }));
+
menu.popup(0, 0, toolbox);
ok(toolbox.doc.querySelector("#menu-popup"), "A popup is in the DOM");
let menuSeparators = toolbox.doc.querySelectorAll("#menu-popup > menuseparator");
is(menuSeparators.length, 1, "A separator is in the menu");
let menuItems = toolbox.doc.querySelectorAll("#menu-popup > menuitem");