Context Menu

Pointer and keyboard menu with nested submenus and an imperative open helper.

Also known as: right click menu, contextual menu

Installation

Install with the CLI, or copy the component source into your project.

Add context-menu (npm)

npx --yes -p github:itsvigneshv/default-file-ui#main df-ui add context-menu

Properties

Pointer and keyboard context menu with nested submenus, typeahead, and an imperative open helper. Mount ContextMenuHost once for openContextMenu.

ContextMenu

PropTypeDefaultNotes
itemsContextMenuEntry[]-Menu tree of actions and separators (required).
openboolean-Controlled open state.
defaultOpenbooleanfalseUncontrolled initial open state.
onOpenChange(open: boolean) => void-Called when open should change.
onSelect(item: ContextMenuActionEntry) => void-Called when an action is chosen, in addition to item.onSelect.
childrenReactElement-Single trigger element. Receives contextmenu and Shift+F10 / ContextMenu key handlers.
classNamestring-Additional classes merged onto the trigger.

ContextMenuActionEntry

PropTypeDefaultNotes
idstring-Stable action id (required).
labelstring-Visible label (required).
glyphReactNode-Leading mark.
shortcutstring-Optional shortcut shown with Kbd.
disabledboolean-Non-selectable item.
destructiveboolean-Destructive visual tone.
onSelect() => void-Per-item select handler.
submenuContextMenuEntry[]-Nested menu opened from this item.

ContextMenuSeparatorEntry

PropTypeDefaultNotes
type"separator"-Marks a separator row.
idstring-Optional stable id for the separator.

ContextMenuHost

Renders the imperative menu session. Mount once near the app root before calling openContextMenu.

openContextMenu

Opens a menu at the pointer or trigger box. Requires ContextMenuHost mounted in the tree. Signature: (event, items) => void.

Keyboard and accessibility

Role (menu): Root and submenu surfaces are menus with menuitem rows. Arrow keys, Home, End, typeahead, Enter, and Escape navigate and dismiss. Placement (anchored): Uses the shared anchored-position hook. After a position attempt the menu stays interactive even when the first measure has no box.