Context Menu
Right-click context menu using the new compositional ContextMenuTrigger and ContextMenuContent subcomponents.
ContextMenu shows a right-click menu for any element. In v0.3.0, shellui add context-menu also installs the compositional ContextMenuTrigger, ContextMenuContent and ContextMenuOption parts. Wrap any element — it will show a right-click floating menu. Menu items are passed as a List<ContextMenuItem> via the Items parameter. The wrapped ChildContent is the right-click target.
Installation
bash
shellui add context-menu
Usage
Basic
Any trigger element
Destructive items
New in v0.4.0: Destructive = true draws an item in the destructive colour, for actions such as Delete. The compositional ContextMenuOption takes Destructive="true" too.
With icons
API Reference
<ContextMenu>
| Parameter | Type | Default | Description |
|---|---|---|---|
Items |
List<ContextMenuItem> |
— | The list of menu items to display |
OnItemSelected |
EventCallback<ContextMenuItem> |
— | Called when the user clicks an item |
ChildContent |
RenderFragment |
— | The element that receives the right-click event |
ContextMenuItem class
| Property | Type | Description |
|---|---|---|
Label |
string |
Displayed text |
Icon |
string? |
Text or emoji rendered before the label (optional) |
Shortcut |
string? |
Shortcut hint shown on the right (optional) |
Disabled |
bool |
Shows the item but ignores clicks |
Destructive |
bool |
Draws the item in the destructive colour (new in 0.4.0) |
IsSeparator |
bool |
Renders a divider instead of an item |
Data |
object? |
Any payload; read it back from the item passed to OnItemSelected |