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 @default-file/ui df-ui add context-menu

Default

Pointer menu with glyphs, shortcut hints, a nested export list, disabled rows, and a destructive action. Opens on load next to the board.

Nested menus

Submenu trees on Export and Share. Hover the row or press Arrow Right to open the nested surface.

Hover Export or Share, or press Arrow Right, to open the nested menu.

Shortcut hints

shortcut renders a Kbd chip on the row. Right click the board to open.

Imperative open

Mount ContextMenuHost, then call openContextMenu from a pointer handler. The helper positions at the event.

Controlled

Parent state owns open. onSelect reports the chosen action in addition to any item handler.

Menu is closed.

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.