{"slug":"context-menu","name":"ContextMenu","category":"Overlays","summary":"Opens a menu at the pointer or from the keyboard Menu key.","status":"stable","since":"0.2.0","import":"import { ContextMenu } from '@elluzion/iv-ui';","usage":["Wrap the area that owns the menu; `entries` uses the same shape as `Menu`.","Right-click opens on pointer devices; `touchTrigger` picks the touch gesture.","Shift+F10 or the Menu key opens it from the keyboard, anchored to the trigger."],"props":[{"name":"entries","type":"MenuEntry[]","default":null,"description":"Menu structure: headers, items, separators, and submenus.","required":true,"bindable":false},{"name":"label","type":"string","default":"''","description":"Accessible name for the menu.","required":false,"bindable":false},{"name":"id","type":"string","default":"''","description":"Element id. A generated id is used when omitted.","required":false,"bindable":false},{"name":"className","type":"string","default":"''","description":"Extra classes merged onto the root element.","required":false,"bindable":false},{"name":"touchTrigger","type":"'longpress' | 'dblclick' | 'click'","default":"'longpress'","description":"Gesture that opens the menu on touch devices.","required":false,"bindable":false}],"events":[{"name":"click","type":"(e: MouseEvent, entry: MenuEntry) => void","default":null,"description":"Called with the native event and the activated entry.","required":false,"bindable":false},{"name":"open","type":"() => void","default":null,"description":"Called after the layer opens.","required":false,"bindable":false},{"name":"close","type":"() => void","default":null,"description":"Called when the layer requests to close.","required":false,"bindable":false}],"snippets":[{"name":"children","type":"Snippet","default":null,"description":"The area that owns the context menu.","required":true,"bindable":false}],"types":[],"manual":[],"tokens":["--iv_border","--iv_popover-max-w","--iv_popover-min-w","--iv_radius","--iv_shadow-md","--iv_spacing-xs","--iv_surface-raised","--iv_z-dropdown"],"cssHooks":["iv-cm-panel","iv-cm-trigger","iv-longpress","iv-menu","iv-ready"],"accessibility":{"keyboard":[["Shift+F10 / Menu","Opens the menu at the trigger."],["Arrow up / down","Moves between items."],["Arrow right / left","Opens or closes a submenu."],["Enter / Space","Activates the focused item."],["Escape","Closes the menu and returns focus to the trigger."]],"notes":["The panel uses `role=\"menu\"` and items use `role=\"menuitem\"`.","Opening moves focus to the first item; closing restores the previous focus.","Clicks outside the panel close it."]},"related":[{"title":"Menu","summary":"A vertical list of commands, options, or links.","url":"/components/menu","kind":"Component"},{"title":"Popover","summary":"A floating panel anchored to an element.","url":"/components/popover","kind":"Component"},{"title":"Dialog","summary":"A modal surface for focused tasks and confirmations.","url":"/components/dialog","kind":"Component"},{"title":"Tooltip","summary":"A short label shown on hover or focus.","url":"/components/tooltip","kind":"Component"}],"examples":[{"id":"basic","title":"Basic","description":"Right-click the panel, or focus it and press Shift+F10.","code":"<script lang=\"ts\">\n\timport type { MenuEntry } from '@elluzion/iv-ui';\n\timport { ContextMenu } from '@elluzion/iv-ui';\n\n\tlet last = $state('none');\n\n\tconst entries: MenuEntry[] = [\n\t\t{ type: 'header', id: 'file', label: 'File' },\n\t\t{ type: 'item', id: 'open', item: { label: 'Open', shortcut: '⏎' } },\n\t\t{ type: 'item', id: 'rename', item: { label: 'Rename', shortcut: 'F2' } },\n\t\t{ type: 'separator', id: 'sep' },\n\t\t{ type: 'item', id: 'delete', item: { label: 'Delete', shortcut: '⌫' } }\n\t];\n\n\tfunction handle(_event: MouseEvent, entry: MenuEntry) {\n\t\tlast = entry.type === 'item' ? entry.item.label : entry.type;\n\t}\n</script>\n\n<div class=\"stack\">\n\t<ContextMenu {entries} label=\"File actions\" onclick={handle}>\n\t\t<div class=\"area\">\n\t\t\t<strong>Right-click this panel</strong>\n\t\t\t<span>or focus it and press Shift+F10</span>\n\t\t</div>\n\t</ContextMenu>\n\t<p class=\"readout\">last action: {last}</p>\n</div>\n\n<style>\n\t.stack {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t\talign-items: center;\n\t\tgap: var(--iv_spacing-sm);\n\t\twidth: 100%;\n\t}\n\n\t.area {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t\talign-items: center;\n\t\tgap: var(--iv_spacing-2xs);\n\t\twidth: 100%;\n\t\tmax-width: 360px;\n\t\tpadding: var(--iv_spacing-2xl);\n\t\tborder: 1px dashed var(--iv_border);\n\t\tborder-radius: var(--iv_radius-sm);\n\t\tbackground: var(--iv_surface-raised);\n\t\tcolor: var(--iv_foreground-dim);\n\t\tfont-family: var(--iv_font-mono);\n\t\tfont-size: var(--iv_text-sm);\n\t}\n\n\t.area strong {\n\t\tcolor: var(--iv_foreground);\n\t\tfont-weight: 500;\n\t}\n\n\t.readout {\n\t\tmargin: 0;\n\t\tfont-family: var(--iv_font-mono);\n\t\tfont-size: var(--iv_text-sm);\n\t\tcolor: var(--iv_foreground-dim);\n\t}\n</style>"},{"id":"submenu","title":"Submenu","description":"A submenu opens on hover or with the right arrow key.","code":"<script lang=\"ts\">\n\timport type { MenuEntry } from '@elluzion/iv-ui';\n\timport { ContextMenu } from '@elluzion/iv-ui';\n\n\tlet last = $state('none');\n\n\tconst entries: MenuEntry[] = [\n\t\t{ type: 'item', id: 'copy', item: { label: 'Copy id', shortcut: '⌘C' } },\n\t\t{\n\t\t\ttype: 'submenu',\n\t\t\tid: 'export',\n\t\t\tlabel: 'Export as',\n\t\t\tchildren: [\n\t\t\t\t{ type: 'item', id: 'json', item: { label: 'JSON' } },\n\t\t\t\t{ type: 'item', id: 'csv', item: { label: 'CSV' } },\n\t\t\t\t{ type: 'item', id: 'yaml', item: { label: 'YAML', disabled: true } }\n\t\t\t]\n\t\t},\n\t\t{ type: 'item', id: 'archive', item: { label: 'Archive' } }\n\t];\n\n\tfunction handle(_event: MouseEvent, entry: MenuEntry) {\n\t\tif (entry.type === 'item') last = entry.item.label;\n\t}\n</script>\n\n<div class=\"stack\">\n\t<ContextMenu {entries} label=\"Record actions\" onclick={handle}>\n\t\t<div class=\"area\">Right-click for the record actions</div>\n\t</ContextMenu>\n\t<p class=\"readout\">last action: {last}</p>\n</div>\n\n<style>\n\t.stack {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t\talign-items: center;\n\t\tgap: var(--iv_spacing-sm);\n\t\twidth: 100%;\n\t}\n\n\t.area {\n\t\twidth: 100%;\n\t\tmax-width: 360px;\n\t\tpadding: var(--iv_spacing-2xl);\n\t\tborder: 1px dashed var(--iv_border);\n\t\tborder-radius: var(--iv_radius-sm);\n\t\tbackground: var(--iv_surface-raised);\n\t\tcolor: var(--iv_foreground-dim);\n\t\tfont-family: var(--iv_font-mono);\n\t\tfont-size: var(--iv_text-sm);\n\t\ttext-align: center;\n\t}\n\n\t.readout {\n\t\tmargin: 0;\n\t\tfont-family: var(--iv_font-mono);\n\t\tfont-size: var(--iv_text-sm);\n\t\tcolor: var(--iv_foreground-dim);\n\t}\n</style>"},{"id":"touch","title":"Touch trigger","description":"`touchTrigger=\"click\"` opens the menu with a tap.","code":"<script lang=\"ts\">\n\timport type { MenuEntry } from '@elluzion/iv-ui';\n\timport { ContextMenu } from '@elluzion/iv-ui';\n\n\tlet last = $state('none');\n\n\tconst entries: MenuEntry[] = [\n\t\t{ type: 'item', id: 'pin', item: { label: 'Pin to top' } },\n\t\t{ type: 'item', id: 'mute', item: { label: 'Mute alerts' } },\n\t\t{ type: 'item', id: 'leave', item: { label: 'Leave workspace' } }\n\t];\n\n\tfunction handle(_event: MouseEvent, entry: MenuEntry) {\n\t\tif (entry.type === 'item') last = entry.item.label;\n\t}\n</script>\n\n<div class=\"stack\">\n\t<ContextMenu {entries} label=\"Workspace actions\" touchTrigger=\"click\" onclick={handle}>\n\t\t<button type=\"button\" class=\"area\">Tap for workspace actions</button>\n\t</ContextMenu>\n\t<p class=\"readout\">last action: {last}</p>\n</div>\n\n<style>\n\t.stack {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t\talign-items: center;\n\t\tgap: var(--iv_spacing-sm);\n\t\twidth: 100%;\n\t}\n\n\t.area {\n\t\tpadding: var(--iv_spacing-md) var(--iv_spacing-lg);\n\t\tborder: 1px solid var(--iv_border);\n\t\tborder-radius: var(--iv_radius-sm);\n\t\tbackground: var(--iv_surface-raised);\n\t\tcolor: var(--iv_foreground);\n\t\tfont-family: var(--iv_font-mono);\n\t\tfont-size: var(--iv_text-sm);\n\t\tcursor: pointer;\n\t}\n\n\t.readout {\n\t\tmargin: 0;\n\t\tfont-family: var(--iv_font-mono);\n\t\tfont-size: var(--iv_text-sm);\n\t\tcolor: var(--iv_foreground-dim);\n\t}\n</style>"}],"markdown":"/components/context-menu.md","page":"/components/context-menu"}