# SbContextMenu A right-click context menu component that appears at the cursor position. ## Parameters | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | Disabled | bool | false | Whether the context menu is disabled | | Class | string? | null | Additional CSS classes | ## Events | Event | Type | Description | |-------|------|-------------| | OnOpen | EventCallback\ | Fired before menu opens (can cancel) | | OnClose | EventCallback | Fired when menu closes | ## Templates / Slots | Slot | Type | Description | |------|------|-------------| | ChildContent | RenderFragment | Content that triggers the context menu | | MenuContent | RenderFragment | Menu items | ## Methods | Method | Return Type | Description | |--------|-------------|-------------| | Close() | Task | Close the context menu | ## SbContextMenuEventArgs Class ```csharp public class SbContextMenuEventArgs { public double X { get; set; } // X coordinate public double Y { get; set; } // Y coordinate public bool Cancel { get; set; } // Set to true to cancel opening } ``` ## CSS Classes - `sb-context-menu-trigger` - Trigger wrapper - `sb-context-menu-overlay` - Backdrop overlay - `sb-context-menu` - Menu container ## Examples ### Basic Usage ```razor
Right-click here for options
``` ### File Browser Context Menu ```razor
document.pdf
``` ### DataGrid Row Context Menu ```razor @row.Item.Name @row.Item.Status ``` ### Conditional Menu Items ```razor
@selectedItem?.Name
@if (canEdit) { } @if (canDelete) { }
@code { private void HandleOpen(SbContextMenuEventArgs args) { // Determine permissions based on context canEdit = currentUser.HasPermission("edit"); canDelete = currentUser.HasPermission("delete"); } } ``` ### Cancel Opening ```razor
Right-click when enabled
@code { private bool isEnabled = false; private void HandleOpen(SbContextMenuEventArgs args) { if (!isEnabled) { args.Cancel = true; // Prevent menu from opening } } } ``` ### Disabled Context Menu ```razor
Document content (context menu disabled in read-only mode)
``` ### Canvas/Drawing Context Menu ```razor @if (selectedShape != null) { } else { } @code { private SbContextMenu canvasContextMenu; private Shape? selectedShape; private void HandleCanvasContextMenu(SbContextMenuEventArgs args) { // Check if a shape is at the click position selectedShape = FindShapeAt(args.X, args.Y); } } ``` ### Tree View Context Menu ```razor @folder.Name ```