Current limitation: The Diagram component does not provide native context menu integration. There are no events like OnShapeContextMenu or OnConnectionContextMenu that fire on right-click. Developers cannot show contextual actions (edit, delete, copy, connect) when user right-clicks on diagram elements.
Requested feature: Add context menu support for Diagram elements:
Use case:
In workflow/process diagram editors, context menu is essential for:
Currently, there is no way to detect right-click on specific diagram elements. The only workaround is complex JavaScript interop to attach event listeners to SVG elements, which is fragile and breaks on re-render.
Example of desired API:
<TelerikDiagram @ref="@DiagramRef"
OnShapeContextMenu="@OnShapeRightClick"
OnConnectionContextMenu="@OnConnectionRightClick"
OnCanvasContextMenu="@OnCanvasRightClick">
<DiagramShapes>
@foreach (var shape in Shapes)
{
<DiagramShape Id="@shape.Id">
<DiagramShapeContent Text="@shape.Name" />
</DiagramShape>
}
</DiagramShapes>
</TelerikDiagram>
<TelerikContextMenu @ref="@ShapeContextMenu"
Data="@ShapeMenuItems"
OnClick="@OnShapeMenuClick">
<ItemTemplate Context="item">
<TelerikFontIcon Icon="@item.Icon" />
<span>@item.Text</span>
</ItemTemplate>
</TelerikContextMenu>
@code {
private TelerikContextMenu<MenuItem>? ShapeContextMenu;
private string? ClickedShapeId;
private async Task OnShapeRightClick(DiagramShapeContextMenuEventArgs args)
{
ClickedShapeId = args.ShapeId;
await ShapeContextMenu.ShowAsync(args.ClientX, args.ClientY);
}
private async Task OnShapeMenuClick(MenuItem item)
{
switch (item.Action)
{
case "edit":
await OpenShapeEditor(ClickedShapeId);
break;
case "delete":
await DeleteShape(ClickedShapeId);
break;
case "duplicate":
await DuplicateShape(ClickedShapeId);
break;
}
}
}Alternative minimal implementation: