Contextual Menu
A menu summoned by right-click (or the keyboard menu key) on a region, opening a
role="menu" of action items at the pointer. Reuses the same headless menu
primitive as DropdownMenu.
Import
Section titled “Import”<script> import ContextMenu from "@invisible-ui/svelte/ContextMenu.svelte";</script><script setup> import { ContextMenu } from "@invisible-ui/vue";</script>import { ContextMenu } from "@invisible-ui/react";<script type="module"> import "@invisible-ui/elements/define";</script>
<ds-context-menu></ds-context-menu>In Elements, the children are the region. Assign the actions through the
items property and listen for select, which fires after the menu closes:
<ds-context-menu label="Page actions"> <div>Right-click here</div></ds-context-menu><script type="module"> import "@invisible-ui/elements/define";
const menu = document.querySelector("ds-context-menu"); menu.items = [ { value: "back", label: "Back" }, { value: "reload", label: "Reload" }, ]; menu.addEventListener("select", (event) => run(event.detail.value));</script>In React, the children are the region. items takes the same entries as
Dropdown Menu, submenus included:
<ContextMenu label="Page actions" items={[ { value: "reload", label: "Reload" }, { type: "submenu", value: "share", label: "Share", items: [{ value: "email", label: "Email" }] }, ]} onSelect={(value) => run(value)}> <div>Right-click here</div></ContextMenu>| Prop | Type | Default | Description |
|---|---|---|---|
items * | MenuItem[] | — | |
disabled | boolean | false | |
onSelect | ((value: string) => void) | undefined | undefined | Called with the chosen item's value. |
label | string | undefined | undefined | Accessible name for the popup (there is no labelling trigger). |
| Prop | Type | Default | Description |
|---|---|---|---|
items * | MenuItem[] | — | |
disabled | boolean | false | |
onSelect | (value: string) => void | undefined | Called with the chosen item's value. |
label | string | undefined | Accessible name for the popup; no trigger labels it. Defaults to the catalog's "Context menu". |
Slots: default.
| Prop | Type | Default | Description |
|---|---|---|---|
items * | MenuEntry[] | — | Items, separators, groups and submenus, in the order shown. |
disabled | boolean | false | |
onSelect | (value: string) => void | — | Called with the chosen item's value, after every level has closed. |
label | string | — | Accessible name for the menu, which has no trigger to name it. Defaults to the catalog's "Context menu". |
children | ReactNode | — | The region the menu opens on. |
| Attribute | Reactive | Description |
|---|---|---|
label | yes | |
disabled | yes |
Reactive attributes re-render the element when they change after the first render.
Properties: items (ContextMenuItem[]: { value, label?, disabled? }).
Emits: bubbling select CustomEvent with detail.value, after the menu closes.
Slot: the default slot is the region the menu is summoned from.
Accessibility
Section titled “Accessibility”- The popup is
role="menu"(named viaaria-label) withrole="menuitem"actions; disabled items carryaria-disabled. - Opens at the pointer on right-click, or at the focused region via the keyboard context-menu key. Arrow / Home / End move, typeahead jumps, Enter/click activates, Escape / Tab / outside-pointer close. DOM focus moves into the menu and is restored to the previously focused element on close.
- Positioning (flip/shift against a virtual anchor at the pointer) via
@floating-ui/dom. The menu opens toward the inline end of the pointer, and from the keyboard at the region’s inline-start top corner: in right-to-left text it opens to the left, from the top right corner. - Under a coarse pointer every item keeps a hit area of at least 44 by 44
(
--ds-metrics-density-touch-min-target-size).
Example
Section titled “Example”<ContextMenu items={[ { value: "reload", label: "Reload" }, { value: "inspect", label: "Inspect" }, ]} onSelect={(v) => run(v)}> <div>Right-click this area</div></ContextMenu>Themeable via the shared --ds-menu-* custom properties.