Skip to content
VinUIComponentsContext Menu

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.

Right-click here, or focus and press Shift+F10
context-menu-basic.html
<div class="vin-context-menu" data-vin-context-menu="cm-file" tabindex="0" style="width: 100%; max-width: 360px">Right-click here, or focus and press Shift+F10</div>
<div class="vin-menu" id="cm-file" popover role="menu" aria-label="File actions">
  <button type="button" class="vin-menu__item" role="menuitem" tabindex="-1"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 20h9"/><path d="M16.4 3.6a2 2 0 0 1 2.9 2.9L7 18.8l-4 1 1-4Z"/></svg>Rename</button>
  <button type="button" class="vin-menu__item" role="menuitem" tabindex="-1"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="12" height="12" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>Duplicate</button>
  <button type="button" class="vin-menu__item" role="menuitem" tabindex="-1"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.7 1.7"/><path d="M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7"/></svg>Copy link</button>
  <div class="vin-menu__separator" role="separator"></div>
  <button type="button" class="vin-menu__item vin-menu__item--danger" role="menuitem" tabindex="-1"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 6h18"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>Delete</button>
</div>

Options and shortcuts

Labels, keyboard shortcuts, and items that turn on and off.

Right-click for view options
context-menu-options.html
<div class="vin-context-menu" data-vin-context-menu="cm-view" tabindex="0" style="width: 100%; max-width: 360px">Right-click for view options</div>
<div class="vin-menu" id="cm-view" popover role="menu" aria-label="View options">
  <button type="button" class="vin-menu__item" role="menuitem" tabindex="-1">Back<span class="vin-menu__shortcut" aria-hidden="true">⌘[</span></button>
  <button type="button" class="vin-menu__item" role="menuitem" tabindex="-1">Reload<span class="vin-menu__shortcut" aria-hidden="true">⌘R</span></button>
  <div class="vin-menu__separator" role="separator"></div>
  <p class="vin-menu__label" role="presentation">Show</p>
  <button type="button" class="vin-menu__item" role="menuitemcheckbox" aria-checked="true" tabindex="-1">Bookmarks bar</button>
  <button type="button" class="vin-menu__item" role="menuitemcheckbox" aria-checked="false" tabindex="-1">Full URLs</button>
  <div class="vin-menu__separator" role="separator"></div>
  <div role="group" aria-label="Zoom">
    <p class="vin-menu__label" role="presentation">Zoom</p>
    <button type="button" class="vin-menu__item" role="menuitemradio" aria-checked="false" tabindex="-1">90%</button>
    <button type="button" class="vin-menu__item" role="menuitemradio" aria-checked="true" tabindex="-1">100%</button>
    <button type="button" class="vin-menu__item" role="menuitemradio" aria-checked="false" tabindex="-1">125%</button>
  </div>
</div>

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:

Terminal
npx @vinish/ui add context-menu
React
import { ContextMenu } from "@/components/vin/context-menu";
Vue
import ContextMenu from "@/components/vin/context-menu.vue";
Svelte
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.

PropValuesDefaultIn HTML
children
The area that opens the menu.
ReactNode—.vin-context-menu[data-vin-context-menu="menu-id"][tabindex=0]
content
The menu's items: DropdownMenuItem, CheckboxItem, RadioGroup, Label and Separator.
ReactNode—.vin-menu#menu-id[popover][role=menu]
label
Name for the menu, read by screen readers.
string—aria-label on the menu
onOpenChange(open: boolean) => void——

Parts

React, Vue, SvelteHTML 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.