Skip to content

Commit

Permalink
#1662 Missing action from submenu causes multiple context-menu cascad…
Browse files Browse the repository at this point in the history
…e menus to appear (#1663)
  • Loading branch information
tomlyn authored Jan 16, 2024
1 parent 1073f7d commit 460561b
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,19 @@ class CommonContextMenu extends React.Component {
return subMenuPosStyle;
}

// Returns the menu definition array passed in making sure any
// submenu items have an action. Note: some applications forget
// to do provide an action because for the submenu it is only
// used by the context menu code.
ensureAllSubMenuItemsHaveAction(menuDef) {
return menuDef.map((item, index) => {
if (item.submenu && typeof item.action === "undefined") {
return { ...item, action: "submenu_" + index };
}
return item;
});
}

render() {
// Reposition contextMenu so that it does not show off the screen
const menuSize = this.calculateMenuSize(this.props.menuDefinition);
Expand All @@ -267,7 +280,8 @@ class CommonContextMenu extends React.Component {
top: menuPos.y + "px"
};

const menuItems = this.buildMenu(this.props.menuDefinition, menuSize, menuPos, this.props.canvasRect);
const menuDefinition = this.ensureAllSubMenuItemsHaveAction(this.props.menuDefinition);
const menuItems = this.buildMenu(menuDefinition, menuSize, menuPos, this.props.canvasRect);

return (
<div id="context-menu-popover" className="context-menu-popover" style={posStyle} onContextMenu={this.onContextMenu}>
Expand Down

0 comments on commit 460561b

Please sign in to comment.