Skip to main content

Starwind UI v2.0 is now available! With new color-picker and more components

Context Menu

Installation

Usage

Basic

A simple context menu with a few actions.

Use ContextMenuSub, ContextMenuSubTrigger, and ContextMenuSubContent to nest secondary actions.

Shortcuts

Add ContextMenuShortcut to show keyboard hints.

With Icons

Combine icons with labels for quick scanning.

Checkboxes

Use ContextMenuCheckboxItem for toggle actions.

Composition

Use the following composition to build a ContextMenu:

ContextMenu
├── ContextMenuTrigger
└── ContextMenuContent
├── ContextMenuGroup
│ ├── ContextMenuLabel
│ ├── ContextMenuItem
│ └── ContextMenuCheckboxItem
├── ContextMenuSeparator
└── ContextMenuSub
├── ContextMenuSubTrigger
└── ContextMenuSubContent
└── ContextMenuGroup
├── ContextMenuItem
└── ContextMenuItem

API Reference

ContextMenu

The root component that serves as a container for all context-menu related components. It uses the Dropdown engine in context-menu mode.

PropTypeDefault
closeDelaynumber200
classstring-
<ContextMenu>
<ContextMenuTrigger>Right click here</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem>Action</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>

Additional Notes:

  • closeDelay: Time in milliseconds to wait before closing related hover interactions for nested content
  • Right-click (or touch long-press) behavior is built in and not configurable through a menuMode prop

ContextMenuTrigger

The area users right-click (or long-press on touch devices) to open the context menu.

PropTypeDefault
classstring-
<ContextMenuTrigger class="rounded-md border border-dashed p-6 text-sm">
Right click here
</ContextMenuTrigger>

Additional Notes:

  • Accepts all native HTMLAttributes<"div"> props
  • Includes built-in accessibility attributes (tabindex="0", aria-haspopup="menu", aria-expanded="false")

ContextMenuContent

The container for context menu content. This component renders the menu with animation effects.

PropTypeDefault
side"top" | "bottom" | "left" | "right""bottom"
align"start" | "center" | "end""start"
sideOffsetnumber4
animationDurationnumber150
classstring-
<ContextMenuContent align="center" sideOffset={8}>
<ContextMenuItem>Open</ContextMenuItem>
</ContextMenuContent>

Additional Notes:

  • side: Side of the menu relative to the trigger ("top", "bottom", "left", or "right")
  • align: Alignment of the menu relative to the trigger
  • sideOffset: Offset distance in pixels from the trigger
  • animationDuration: Open and close animation duration in milliseconds

ContextMenuItem

A component for creating interactive items within the context menu.

PropTypeDefault
asHTMLTag"div"
insetbooleanfalse
disabledbooleanfalse
classstring-
<ContextMenuItem as="a" href="#">Open link</ContextMenuItem>

Additional Notes:

  • as: HTML element to render the item as (for example, "a" or "button")
  • inset: Whether the item has left padding for alignment with items that have icons

ContextMenuLabel

A component for rendering a non-interactive label within the context menu.

PropTypeDefault
insetbooleanfalse
classstring-
<ContextMenuLabel>Section Title</ContextMenuLabel>

Additional Notes:

  • inset: Whether the label has left padding for alignment with items that have icons

ContextMenuSeparator

A component for creating a visual separator between context menu items.

PropTypeDefault
classstring-
<ContextMenuSeparator />

ContextMenuCheckboxItem

A component for creating checkbox items within the context menu. It includes a built-in check indicator and emits a custom event when toggled.

PropTypeDefault
checkedbooleanfalse
closeOnClickbooleanfalse
insetbooleanfalse
disabledbooleanfalse
classstring-
<ContextMenuCheckboxItem checked>
Show status bar
</ContextMenuCheckboxItem>

Additional Notes:

  • checked: Controls the initial checked state of the item
  • closeOnClick: Whether the menu should close when the checkbox item is clicked
  • inset: Whether the item has left padding for alignment with items that have icons
  • disabled: Prevents interaction and keyboard focus
  • Emits a starwind-dropdown-checkbox:change custom event with { checked: boolean } detail when toggled

ContextMenuGroup

A wrapper component for grouping related context menu items together. It applies the role="group" attribute for accessibility.

PropTypeDefault
classstring-
<ContextMenuGroup>
<ContextMenuLabel>Team</ContextMenuLabel>
<ContextMenuItem>Invite users</ContextMenuItem>
<ContextMenuItem>New Team</ContextMenuItem>
</ContextMenuGroup>

ContextMenuShortcut

An optional helper for rendering keyboard hints aligned to the end of a context menu item.

PropTypeDefault
classstring-
<ContextMenuItem>
Profile
<ContextMenuShortcut>Shift+Ctrl+P</ContextMenuShortcut>
</ContextMenuItem>

ContextMenuSub

A wrapper for submenu trigger and content pairs inside a context menu.

PropTypeDefault
classstring-
<ContextMenuSub>
<ContextMenuSubTrigger>Invite users</ContextMenuSubTrigger>
<ContextMenuSubContent>
<ContextMenuItem>Email</ContextMenuItem>
</ContextMenuSubContent>
</ContextMenuSub>

ContextMenuSubTrigger

The interactive trigger that opens a nested submenu.

PropTypeDefault
insetbooleanfalse
disabledbooleanfalse
classstring-
<ContextMenuSubTrigger inset>Invite users</ContextMenuSubTrigger>

Additional Notes:

  • inset: Adds left padding to align with items that include icons
  • disabled: Prevents interaction and keyboard focus

ContextMenuSubContent

The content panel rendered when a submenu trigger is opened.

PropTypeDefault
animationDurationnumber150
sideOffsetnumber0
classstring-
<ContextMenuSubContent animationDuration={200}>
<ContextMenuItem>Email</ContextMenuItem>
<ContextMenuItem>Message</ContextMenuItem>
</ContextMenuSubContent>

Additional Notes:

  • animationDuration: Open and close animation duration in milliseconds
  • sideOffset: Offset distance in pixels from the submenu trigger

Changelog

v1.0.0

  • Initial Release with Starwind v2.0.0
  • Built on shared Dropdown primitives with context-menu behavior