Context Menu
A menu that opens where you right-click or long-press, with the same items as Dropdown Menu. Same markup and props in every style: switch the style in the header to see it change.
Basic
Right-click the area, long-press it on a touch screen, or focus it and press Shift+F10 or the Menu key. In HTML, add data-vin-context-menu and include vinui.js once.
Options and shortcuts
Labels, keyboard shortcuts, and items that turn on and off.
Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add context-menuimport { ContextMenu } from "@/components/vin/context-menu";import ContextMenu from "@/components/vin/context-menu.vue";import ContextMenu from "$lib/components/vin/context-menu.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.
API
From spec/context-menu.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
childrenThe area that opens the menu. | ReactNode | — | .vin-context-menu[data-vin-context-menu="menu-id"][tabindex=0] |
contentThe menu's items: DropdownMenuItem, CheckboxItem, RadioGroup, Label and Separator. | ReactNode | — | .vin-menu#menu-id[popover][role=menu] |
labelName for the menu, read by screen readers. | string | — | aria-label on the menu |
onOpenChange | (open: boolean) => void | — | — |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<ContextMenu> | .vin-context-menu |
Accessibility
- The menu is the Dropdown Menu: role="menu", arrow keys, Home and End, type to jump, Esc or Tab to close.
- The area is focusable, and Shift+F10 or the Menu key opens the menu at its corner, so it works without a mouse.
- Focus goes into the menu when it opens and back to the area when it closes.
- Shift+right-click still shows the browser's own menu.
- Don't hide actions only in a context menu: offer them somewhere visible too.
Customize
Saved in this browser. Style and accent are in the header.