Hi, I’m brand new to Dojo – just started today.
I’m trying to add a context menu to each tab in a TabContainer
. This seems easy enough to do (see my example below). The problem is that if I mark a tab as closable
then this seems to auto-generate a context menu that overrides mine.
Thus, in the example below, if you right-click on the “Group One” tab, my context menu comes up. Great.
However, if you right-click on the “Group Two” tab then instead what you get is a context menu with exactly one option: “Close”.
How can I either:
1. Replace the auto-generated “Close” menu with the one I want, or
2. Add the MemuItem
s I want to the auto-generated Menu
?
Or is there some other solution? Thanks.
EDIT: Here’s a fiddle: https://jsfiddle.net/j96w02hu/
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Tab Context Menu Issues</title>
<style>
html, body {
height: 100%;
margin: 0;
overflow: hidden;
padding: 0;
}
#appLayout {
height: 100%;
}
</style>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/claro/claro.css" media="screen">
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js" data-dojo-config="async: 1"></script>
<script>
require(["dijit/registry",
"dijit/layout/TabContainer", "dijit/layout/ContentPane",
"dijit/Menu", "dijit/MenuItem",
"dojo/domReady!"],
function(registry, TabContainer, ContentPane, Menu, MenuItem){
// create the TabContainer and attach it to our appLayout div
var appLayout = new TabContainer({
id: "contentTabs",
tabPosition: "top",
"class": "centerPanel"
}, "appLayout");
// Add tabs
appLayout.addChild(
new ContentPane({
title: "Group One",
content: "<h4>Group 1 Content</h4>"
})
);
appLayout.addChild(
new ContentPane({
title: "Group Two",
content: "<h4>Group 2 Content</h4>",
closable: true
})
);
// start up and do layout
appLayout.startup();
// Add context menus.
var pMenu;
pMenu = new Menu({
targetNodeIds: ["contentTabs"],
selector: ".dijitTab"
});
pMenu.addChild(new MenuItem({
label: "Simple menu item"
}));
pMenu.addChild(new MenuItem({
label: "Disabled menu item",
disabled: true
}));
pMenu.startup();
}
);
</script>
</head>
<body class="claro">
<div id="appLayout" class="demoLayout"></div>
</body>
</html>
(Note: you may have to right-click twice in order to get the context menu to come up. But, one problem at a time…)