ContextMenu
A right-click menu for any element, opened at the cursor or from the keyboard with Shift+F10 or the Menu key.
Installation
npx dafink-ui add context-menuAlso installs: Menu
Demo
Last action: none
Props
| Name | Type | Default | Description |
|---|---|---|---|
| items | MenuLeafEntry[] | - | Entries: { label, onSelect?, disabled?, selected?, detail? } or { separator: true }. Submenus are not supported. |
| children | ReactNode | - | The region that opens the menu on right-click, or on Shift+F10 / the Menu key when focus is inside it. |
| label | string | 'Context menu' | Accessible name for the menu. |
| disabled | boolean | false | Never opens; the browser's native menu shows instead. |
| onOpenChange | (open: boolean) => void | - | Called when the menu opens or closes. |
| className | string | '' | Additional classes on the menu panel. |
Accessibility
Right-clicking anywhere in the wrapped region opens a role="menu" at the cursor; keyboard users open the same menu with Shift+F10 or the Menu key while focus is inside the region, anchored to the focused element. Focus moves into the menu, which uses aria-activedescendant for the active item, and isn't trapped: Escape, Tab, or choosing an item closes it and returns focus to the element that opened it. A pointer press outside, a scroll, or a resize closes it without moving focus. Items and their disabled/selected states render through the same code as Menu, so the two can't drift apart.
| Key | Function |
|---|---|
| shift+f10 | Opens the menu for the focused element. |
| menu | Opens the menu for the focused element (the context menu key). |
| down arrow | Moves to the next item, skipping disabled items and wrapping. |
| up arrow | Moves to the previous item, wrapping. |
| home | Moves to the first item. |
| end | Moves to the last item. |
| enter | Activates the item and closes the menu. |
| space | Activates the item and closes the menu. |
| escape | Closes the menu and returns focus. |
| tab | Closes the menu and returns focus. |
On touch screens, a half-second long-press opens the same menu at your finger; moving more than a few pixels cancels it, so scrolling and dragging still work.