ContextMenu
Wrap an area and give it items; right-clicking inside opens a custom menu at the pointer instead of the default browser menu. The items are the same as Menu: icons, shortcut hints, dividers, tone="danger" and nested children. Arrow keys move, Enter chooses, Escape or an outside click closes it, and the Menu key opens it from the keyboard. Right-clicking again elsewhere moves it. disabled hands the click back to the browser.
Last action: nothing yet
Props
ContextMenu
childrenReactNodeThe area that opens the menu when right-clicked.
itemsMenuItem[]The entries, as in
Menu.childrenmakes a submenu;{ key, divider: true }is a separator. See the MenuItem table below.labelstringAccessible name of the menu.
disabledbooleanDefault:falseLeave the browser's own context menu alone.
look'default' | 'actions'Default:'default'The look of the menu: "actions" matches ActionMenu (uppercase labels, ruled rows, a fixed width); the default is the compact one.
linkComponentElementTypeDefault:'a'Component used for items with a site path as href (not absolute URLs), e.g. a router Link.
linkPropstringDefault:'href'Prop that receives the href on linkComponent, e.g. "to".
onOpenChange(open: boolean) => voidCalled when it opens or closes.
classNamestringDefault:''Extra classes for the root element.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | – | The area that opens the menu when right-clicked. |
items | MenuItem[] | – | The entries, as in Menu. children makes a submenu; { key, divider: true } is a separator. See the MenuItem table below. |
label | string | – | Accessible name of the menu. |
disabled | boolean | false | Leave the browser's own context menu alone. |
look | 'default' | 'actions' | 'default' | The look of the menu: "actions" matches ActionMenu (uppercase labels, ruled rows, a fixed width); the default is the compact one. |
linkComponent | ElementType | 'a' | Component used for items with a site path as href (not absolute URLs), e.g. a router Link. |
linkProp | string | 'href' | Prop that receives the href on linkComponent, e.g. "to". |
onOpenChange | (open: boolean) => void | – | Called when it opens or closes. |
className | string | '' | Extra classes for the root element. |
MenuItem
keystringUnique key of the item.
labelReactNodeText of the item (not needed for a divider or heading).
headingReactNodeA group label instead of an item; the items after it, up to the next heading or divider, are grouped under it.
itemsMenuItem[]Makes the item a group: its label is the heading and these are the items under it (dividers and submenus work inside).
iconReactNodeShown before the label, hidden from screen readers.
descriptionReactNodeA smaller grey line under the label.
badgeReactNodeShort value at the end of the row, e.g. a count.
shortcutstringA keyboard shortcut hint at the end, e.g. "Ctrl+C" (display only).
disabledbooleanDefault:falseDim the item and ignore it.
tone'default' | 'warning' | 'danger'Default:'default'Color of the item; "danger" is red, for destructive actions.
hasDialogbooleanDefault:falseMarks an item that opens a dialog (aria-haspopup="dialog").
hrefstringMakes the item a real link instead of a button; onClick is then optional.
targetstringFor link items: where to open it. "_blank" opens a new tab and adds rel="noopener noreferrer".
externalbooleanShow the external-link arrow. By default a link is external when it has target="_blank" or an absolute http(s) address.
onClick() => voidCalled when the item is chosen.
childrenMenuItem[]Makes the item open a submenu with these items.
dividerbooleanDefault:falseA separator line instead of an item (only key is needed).
| Prop | Type | Default | Description |
|---|---|---|---|
key | string | – | Unique key of the item. |
label | ReactNode | – | Text of the item (not needed for a divider or heading). |
heading | ReactNode | – | A group label instead of an item; the items after it, up to the next heading or divider, are grouped under it. |
items | MenuItem[] | – | Makes the item a group: its label is the heading and these are the items under it (dividers and submenus work inside). |
icon | ReactNode | – | Shown before the label, hidden from screen readers. |
description | ReactNode | – | A smaller grey line under the label. |
badge | ReactNode | – | Short value at the end of the row, e.g. a count. |
shortcut | string | – | A keyboard shortcut hint at the end, e.g. "Ctrl+C" (display only). |
disabled | boolean | false | Dim the item and ignore it. |
tone | 'default' | 'warning' | 'danger' | 'default' | Color of the item; "danger" is red, for destructive actions. |
hasDialog | boolean | false | Marks an item that opens a dialog (aria-haspopup="dialog"). |
href | string | – | Makes the item a real link instead of a button; onClick is then optional. |
target | string | – | For link items: where to open it. "_blank" opens a new tab and adds rel="noopener noreferrer". |
external | boolean | – | Show the external-link arrow. By default a link is external when it has target="_blank" or an absolute http(s) address. |
onClick | () => void | – | Called when the item is chosen. |
children | MenuItem[] | – | Makes the item open a submenu with these items. |
divider | boolean | false | A separator line instead of an item (only key is needed). |