Native Solid 2 fork. Original documentation and designs © WorkOS; historical posts retain their original context.
Context Menu
Displays a menu located at the pointer, triggered by a right click or a long press.
Features
Supports submenus with configurable reading direction.
Supports items, labels, groups of items.
Supports checkable items (single or multiple) with optional indeterminate state.
Supports modal and non-modal modes.
Customize side, alignment, offsets, collision handling.
Focus is fully managed.
Full keyboard navigation.
Typeahead support.
Dismissing and layering behavior is highly customizable.
Triggers with a long press on touch devices
Anatomy
Import all parts and piece them together.
API Reference
Adheres to the Menu WAI-ARIA design pattern and uses roving tabindex to manage focus movement among menu items.
Root
Contains all the parts of a context menu.
Trigger
The area that opens the context menu. Wrap it around the target you want the context menu to open from when right-clicking (or using the relevant keyboard shortcuts).
Portal
When used, portals the content part into the body.
Content
The component that pops out in an open context menu.
Arrow
An optional arrow element to render alongside a submenu. This can be used to help visually link the trigger item with the ContextMenu.Content. Must be rendered inside ContextMenu.Content.
Item
The component that contains the context menu items.
Group
Used to group multiple ContextMenu.Items.
Label
Used to render a label. It won't be focusable using arrow keys.
CheckboxItem
An item that can be controlled and rendered like a checkbox.
RadioGroup
Used to group multiple ContextMenu.RadioItems.
RadioItem
An item that can be controlled and rendered like a radio.
ItemIndicator
Renders when the parent ContextMenu.CheckboxItem or ContextMenu.RadioItem is checked. You can style this element directly, or you can use it as a wrapper to put an icon into, or both.
Separator
Used to visually separate items in the context menu.
Sub
Contains all the parts of a submenu.
SubTrigger
An item that opens a submenu. Must be rendered inside ContextMenu.Sub.
SubContent
The component that pops out when a submenu is open. Must be rendered inside ContextMenu.Sub.
Examples
With submenus
You can create submenus by using ContextMenu.Sub in combination with its parts.
With disabled items
You can add special styles to disabled items via the data-disabled attribute.
With separators
Use the Separator part to add a separator between items.
With labels
Use the Label part to help label a section.
With checkbox items
Use the CheckboxItem part to add an item that can be checked.
With radio items
Use the RadioGroup and RadioItem parts to add an item that can be checked amongst others.
With complex items
You can add extra decorative elements in the Item parts, such as images.
Constrain the content/sub-content size
You may want to constrain the width of the content (or sub-content) so that it matches the trigger (or sub-trigger) width. You may also want to constrain its height to not exceed the viewport.
We expose several CSS custom properties such as --radix-context-menu-trigger-width and --radix-context-menu-content-available-height to support this. Use them to constrain the content dimensions.
Origin-aware animations
We expose a CSS custom property --radix-context-menu-content-transform-origin. Use it to animate the content from its computed origin based on side, sideOffset, align, alignOffset and any collisions.
Collision-aware animations
We expose data-side and data-align attributes. Their values will change at runtime to reflect collisions. Use them to create collision and direction-aware animations.
Accessibility
Uses roving tabindex to manage focus movement among menu items.