Skip to main content

Starwind UI v3.0 beta is now available! Read the migration guide

Context Menu

Runtime example adjustment

Destructive actions are styled from Runtime item states instead of a legacy variant. The checkbox uses defaultChecked so Runtime can own its later toggles rather than receiving an immutable checked value.

Installation

Framework Availability

Astro Available React Available

Context Menu is available for Astro and React.

Usage

Basic

A simple context menu with a few actions.

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

Runtime example adjustment

Nested context menus now use the dedicated Runtime submenu anatomy; destructive actions are styled from the item state instead of a removed item variant.

Shortcuts

Add ContextMenuShortcut to show keyboard hints.

With Icons

Combine icons with labels for quick scanning.

Runtime example adjustment

Runtime context-menu items no longer provide a destructive variant, so the example styles that action directly while preserving highlighted and focus states.

Checkboxes

Use ContextMenuCheckboxItem for toggle actions.

Runtime example adjustment

Interactive checkbox items use defaultChecked for their initial uncontrolled state, allowing the Runtime menu controller to toggle them after hydration.

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

Styled Component API

These props are added or materially changed by the installed Astro styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Follow the Primitive and Runtime links for lower-level behavior props.

Context Menu Item

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
inset boolean false
Description
Adds leading inset spacing for visual alignment.
Classification
Wrapper prop

Context Menu Checkbox Item

Inherits div attributes. Omits `aria-checked` and `role`.

Contains the following additional props:

Prop Type Default Toggle details
closeOnClick boolean false
Description
Closes the containing surface after the item is activated.
Classification
Wrapper prop
indicatorClass string
Description
Adds classes to the generated selection indicator.
Classification
Wrapper prop
inset boolean false
Description
Adds leading inset spacing for visual alignment.
Classification
Wrapper prop
showIndicator boolean true
Description
Shows the generated selection indicator.
Classification
Wrapper prop

Context Menu Radio Item

Inherits div attributes. Omits `aria-checked` and `role`.

Contains the following additional props:

Prop Type Default Toggle details
closeOnClick boolean false
Description
Closes the containing surface after the item is activated.
Classification
Wrapper prop
indicatorClass string
Description
Adds classes to the generated selection indicator.
Classification
Wrapper prop
inset boolean false
Description
Adds leading inset spacing for visual alignment.
Classification
Wrapper prop
showIndicator boolean true
Description
Shows the generated selection indicator.
Classification
Wrapper prop
value Required string
Description
Controls or identifies the component value.
Classification
Wrapper prop

Context Menu Label

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
inset boolean false
Description
Adds leading inset spacing for visual alignment.
Classification
Wrapper prop

Context Menu Sub Trigger

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
inset boolean false
Description
Adds leading inset spacing for visual alignment.
Classification
Wrapper prop

Context Menu Sub Content

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
side "top" | "right" | "bottom" | "left" "right"
Description
Selects the preferred side for floating content.
Classification
Primitive override
Primitive prop
context-menu.Popup.side
sideOffset number 0
Description
Sets the distance in pixels between floating content and its anchor.
Classification
Primitive override
Primitive prop
context-menu.Popup.sideOffset

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Context Menu.

Runtime API

Context Menu primitive
createContextMenu from @starwind-ui/runtime/context-menu

Changelog

v2.0.0

  • Rebuilt Context Menu on Starwind Runtime for opening, keyboard navigation, submenus, and checked items.
  • See the Context Menu Primitive for the underlying unstyled anatomy and behavior API.