Context Menu
A menu opened at the pointer by right-click or long-press.
MarkdownExamples
Basic
As in Menu, { separator: true } draws a line between groups.
report.pdfRight-click, long-press, or focus and press Shift+F10
API
| Prop | Type | Default |
|---|---|---|
itemsMenu items in order; | MenuEntry<T>[] | [] |
labelAccessible name for the menu. Defaults to the | string | — |
disabledLeaves the browser's own context menu in place. | boolean | false |
openWhether the menu is open. | boolean | false |
| Event | Payload |
|---|---|
selectAn item was activated. | [value: T] |
update:open
| [value: boolean] |
| Slot | Props |
|---|---|
defaultThe area that opens the menu on right-click, long-press, or Shift+F10. | — |
itemItem content. | { item: MenuItem<T>; active: boolean; } |
Types
export type MenuEntry<T extends SelectValue = SelectValue> = MenuItem<T> | MenuSeparator;
export interface MenuItem<T extends SelectValue = SelectValue> extends SelectOption<T> {
/** Trailing text, e.g. a shortcut like "⌘S". Render richer content via the `item` slot. */
hint?: string;
}
export type SelectValue = string | number;
/** A line between groups of menu items. */
export interface MenuSeparator {
separator: true;
}
export interface SelectOption<T extends SelectValue = SelectValue> {
label: string;
value: T;
disabled?: boolean;
}Copy codeStyling
Its items use Menu's styling hooks.
- Parts
context-menucontext-menu-anchormenu-listmenu-separatormenu-itemmenu-item-labelmenu-item-hint- States
data-context-menu-opendata-menu-indexdata-menu-active
Keyboard
| Keys | Action |
|---|---|
Shift + F10 / Menu key | Open from the focused element |
↓ / ↑ | Move between items |
Home / End | First / last item |
| Letters | Jump to an item by label |
Enter / Space | Activate |
Escape | Close and return focus |
Accessibility
- Make the area focusable (
tabindex="0") so keyboard users can open it. - Long-press opens it on touch, including iOS Safari, which has no
contextmenuevent.