Import
import {
ContextMenu ,
ContextMenuTrigger ,
ContextMenuContent ,
ContextMenuItem ,
ContextMenuShortcut ,
ContextMenuSub ,
ContextMenuSubTrigger ,
ContextMenuSubContent ,
ContextMenuSeparator ,
ContextMenuCheckboxItem
} from '@strongtie/design-system/context-menu' ;
Usage
< ContextMenu >
< ContextMenuTrigger > Right click here </ ContextMenuTrigger >
< ContextMenuContent >
< ContextMenuItem inset >
Back
< ContextMenuShortcut > ⌘[ </ ContextMenuShortcut >
</ ContextMenuItem >
< ContextMenuItem inset disabled >
Forward
< ContextMenuShortcut > ⌘] </ ContextMenuShortcut >
</ ContextMenuItem >
< ContextMenuItem inset >
Reload
< ContextMenuShortcut > ⌘R </ ContextMenuShortcut >
</ ContextMenuItem >
< ContextMenuSeparator />
< ContextMenuCheckboxItem checked >
Show Bookmarks
</ ContextMenuCheckboxItem >
< ContextMenuCheckboxItem >
Show Full URLs
</ ContextMenuCheckboxItem >
</ ContextMenuContent >
</ ContextMenu >
If true, the trigger will render as a child component.
When true, the context menu won’t open.
An offset in pixels from the “start” or “end” alignment options.
When true, overrides the side and align preferences to prevent collisions with boundary edges.
collisionBoundary
Element | null | Array<Element | null>
default: "[]"
The element used as the collision boundary.
collisionPadding
number | Partial<Record<Side, number>>
default: "0"
The distance in pixels from the boundary edges where collision detection should occur.
sticky
"partial" | "always"
default: "\"partial\""
The sticky behavior on the align axis.
When true, the item will have an inset appearance.
When true, prevents the user from interacting with the item.
Event handler called when the user selects an item.
Optional text used for typeahead purposes.
checked
boolean | 'indeterminate'
The controlled checked state of the item.
onCheckedChange
(checked: boolean) => void
Event handler called when the checked state changes.
When true, prevents the user from interacting with the item.
The open state of the submenu when it is initially rendered.
The controlled open state of the submenu.
Event handler called when the open state of the submenu changes.
Usage Examples Basic
With Shortcuts
With Checkbox Items
With Submenu
< ContextMenu >
< ContextMenuTrigger >
Right click me
</ ContextMenuTrigger >
< ContextMenuContent >
< ContextMenuItem >
Profile
</ ContextMenuItem >
< ContextMenuItem >
Settings
</ ContextMenuItem >
< ContextMenuSeparator />
< ContextMenuItem >
Logout
</ ContextMenuItem >
</ ContextMenuContent >
</ ContextMenu >
Styling Classes The component applies the following CSS classes:
context-menu-content - Applied to the main content container
context-menu-sub-content - Applied to submenu content containers
menu-item - Applied to all menu items (regular, checkbox, radio, label)
menu-item-sub-trigger - Applied to submenu trigger items
menu-item-checkbox - Applied to checkbox menu items
menu-item-radio - Applied to radio menu items
menu-item-label - Applied to label menu items
menu-item-indicator - Applied to checkbox/radio indicator spans
menu-item-separator - Applied to separator elements
menu-item-shortcut - Applied to shortcut text elements
For more examples, visit the Storybook . @inject ContextMenuService ContextMenuService
< StudsButton Text = "Right click me" ContextMenu = @(args = > ShowContextMenu(args)) />
@code {
void ShowContextMenu ( MouseEventArgs args )
{
ContextMenuService . Open ( args ,
new List < ContextMenuItem > {
new ContextMenuItem (){ Text = "Copy" , Value = 1 , Icon = "content_copy" },
new ContextMenuItem (){ Text = "Paste" , Value = 2 , Icon = "content_paste" , Disabled = true },
new ContextMenuItem (){ Text = "Delete" , Value = 3 , Icon = "delete" },
}, OnMenuItemClick );
}
void OnMenuItemClick ( MenuItemEventArgs args )
{
ContextMenuService . Close ();
// Handle menu item click
}
}
Opens a context menu with the specified items and click handler.
Opens a context menu with custom content.
Closes the currently open context menu.
The display text for the menu item.
The value associated with the menu item, passed to the click handler.
The icon name to display next to the text.
Image URL to display instead of an icon.
CSS styles to apply to the image.
Whether the menu item is disabled.
Usage Examples Basic
With Icons
With Disabled Items
Custom Content
@inject ContextMenuService ContextMenuService
< StudsButton Text = "Right click me" ContextMenu = @ShowBasicContextMenu />
@code {
void ShowBasicContextMenu ( MouseEventArgs args )
{
ContextMenuService . Open ( args ,
new List < ContextMenuItem > {
new ContextMenuItem (){ Text = "Profile" , Value = "profile" },
new ContextMenuItem (){ Text = "Settings" , Value = "settings" },
new ContextMenuItem (){ Text = "Logout" , Value = "logout" },
}, OnMenuClick );
}
void OnMenuClick ( MenuItemEventArgs args )
{
ContextMenuService . Close ();
// Handle the selected value
}
}
Events The context menu service provides several events for handling navigation and state changes:
OnOpen - Fired when a context menu is opened
OnClose - Fired when a context menu is closed
OnNavigate - Fired when navigation occurs (automatically closes menus)
Styling Classes The following CSS classes are applied by the Context Menu components:
context-menu – Root context menu container
tooltip – Positioned container for the context menu
For more examples, visit the Storybook .