Skip to content

Search documentation

Search guides, examples, and component APIs.

Quick links
↑↓ NavigateEnter OpenEsc Close
Get started

Documentation navigation

Components / Overlays

ContextMenu

A pointer-, keyboard-, and long-press-invoked menu positioned at the interaction point.

Last changed in version 0.14.2: Improve keyboard navigation, action feedback, and selected colors across Vue components.

Interactive showcase

Project row Right-click or press Shift+F10

Install

Run in your project
bunx --bun @getweini/cli@latest add context-menu

Start with this example

Import the files copied by the install command, then place the component in your Vue template. The text and values in the example belong to your app; change them to fit your task.

Quarterly report.pdf
Vue
<script setup lang="ts">
import ContextMenu from './components/ui/context-menu/ContextMenu.vue'
import ContextMenuContent from './components/ui/context-menu/ContextMenuContent.vue'
import ContextMenuItem from './components/ui/context-menu/ContextMenuItem.vue'
import ContextMenuTrigger from './components/ui/context-menu/ContextMenuTrigger.vue'
</script>
<template>
  <ContextMenu @select="$emit('fileAction', $event.id)">
    <ContextMenuTrigger tabindex="0">Quarterly report.pdf</ContextMenuTrigger>
    <ContextMenuContent aria-label="File actions">
      <ContextMenuItem id="open" label="Open">Open</ContextMenuItem>
      <ContextMenuItem id="duplicate" label="Duplicate">Duplicate</ContextMenuItem>
    </ContextMenuContent>
  </ContextMenu>
</template>

Open the menu with right-click, the keyboard, or a long press. Add #prefix and #suffix content to action, checkbox, radio, and submenu items; shortcuts stay between the label and suffix.

When to use it

File actions

Offer context-specific commands on a file tile through right-click, keyboard, or long press.

Selected item menu

Apply commands to the exact item whose trigger opened the menu.

More examples

File commands

ContextMenuItem uses the installed context-menu child.

File commands
<script setup lang="ts">
import ContextMenu from './components/ui/context-menu/ContextMenu.vue'
import ContextMenuContent from './components/ui/context-menu/ContextMenuContent.vue'
import ContextMenuItem from './components/ui/context-menu/ContextMenuItem.vue'
import ContextMenuTrigger from './components/ui/context-menu/ContextMenuTrigger.vue'
</script>
<template>
  <ContextMenu @select="$emit('fileAction', $event.id)">
    <ContextMenuTrigger tabindex="0">Quarterly report.pdf</ContextMenuTrigger>
    <ContextMenuContent aria-label="File actions">
      <ContextMenuItem id="open" label="Open">Open</ContextMenuItem>
      <ContextMenuItem id="duplicate" label="Duplicate">Duplicate</ContextMenuItem>
    </ContextMenuContent>
  </ContextMenu>
</template>

Destructive choice

Keep the destructive action distinct from ordinary commands.

Destructive choice
<script setup lang="ts">
import ContextMenu from './components/ui/context-menu/ContextMenu.vue'
import ContextMenuContent from './components/ui/context-menu/ContextMenuContent.vue'
import ContextMenuItem from './components/ui/context-menu/ContextMenuItem.vue'
import ContextMenuSeparator from './components/ui/context-menu/ContextMenuSeparator.vue'
import ContextMenuTrigger from './components/ui/context-menu/ContextMenuTrigger.vue'
</script>
<template>
  <ContextMenu :long-press-delay="700" @select="$emit('action', $event.id)">
    <ContextMenuTrigger tabindex="0">Project card</ContextMenuTrigger>
    <ContextMenuContent aria-label="Project actions">
      <ContextMenuItem id="share" label="Share">Share</ContextMenuItem>
      <ContextMenuSeparator />
      <ContextMenuItem id="archive" label="Archive" destructive>Archive</ContextMenuItem>
    </ContextMenuContent>
  </ContextMenu>
</template>

Complete API

Every public prop, model, event, slot, and exposed member of the installed Vue parts is listed below. “Not set” means you can leave that value out; “Required” means you must provide it. Native HTML attributes also work where the component uses a native element.

ContextMenu

Complete API for ContextMenu
NameType or signatureDefaultWhat it does
openmodelboolean | undefinedNot setCurrent open state. Use v-model:open to keep it in sync with your page.
defaultOpenpropboolean | undefinedNot setStarting open state when the parent does not control open.
disabledpropboolean | undefinedNot setPrevent interaction and show the disabled state.
widthpropnumber | undefined224Choose the width of this content.
gappropnumber | undefined0Space in pixels between the trigger and floating content.
dirprop"ltr" | "rtl" | undefined"ltr"Set the text direction used for keyboard and layout behavior.
longPressDelaypropnumber | undefined600Time a touch must be held before opening the menu.
selectevent[action: DropdownMenuAction]—Emitted when the user selects an item.
update:openevent[value: boolean | undefined]—Requests a new open value from the parent.
openChangeevent[open: boolean]—Emitted after this value or state changes.
defaultslot{}OptionalContent shown inside ContextMenu.

ContextMenuCheckboxItem

Complete API for ContextMenuCheckboxItem
NameType or signatureDefaultWhat it does
idpropstringRequiredGive the control an ID so a label or description can refer to it.
labelpropstringRequiredVisible or accessible name for this item.
checkedpropboolean | undefinedNot setCurrent checked state of this choice.
disabledpropboolean | undefinedNot setPrevent interaction and show the disabled state.
destructivepropboolean | undefinedNot setShow that an action has a potentially destructive result.
shortcutpropstring | undefinedNot setKeyboard shortcut displayed beside this action.
defaultslot{}OptionalContent shown inside ContextMenuCheckboxItem.
prefixslot{}OptionalContent shown before the main label or value.
suffixslot{}OptionalContent shown after the main label or value.

ContextMenuContent

Complete API for ContextMenuContent
NameType or signatureDefaultWhat it does
defaultslot{}OptionalContent shown inside ContextMenuContent.

ContextMenuGroup

Complete API for ContextMenuGroup
NameType or signatureDefaultWhat it does
defaultslot{}OptionalContent shown inside ContextMenuGroup.

ContextMenuItem

Complete API for ContextMenuItem
NameType or signatureDefaultWhat it does
defaultslot{}OptionalContent shown inside ContextMenuItem.
prefixslot{}OptionalContent shown before the main label or value.
suffixslot{}OptionalContent shown after the main label or value.

ContextMenuLabel

Complete API for ContextMenuLabel
NameType or signatureDefaultWhat it does
defaultslot{}OptionalContent shown inside ContextMenuLabel.

ContextMenuRadioGroup

Complete API for ContextMenuRadioGroup
NameType or signatureDefaultWhat it does
defaultslot{}OptionalContent shown inside ContextMenuRadioGroup.

ContextMenuRadioItem

Complete API for ContextMenuRadioItem
NameType or signatureDefaultWhat it does
idpropstringRequiredGive the control an ID so a label or description can refer to it.
valuepropstringRequiredValue represented by this control or option.
labelpropstringRequiredVisible or accessible name for this item.
disabledpropboolean | undefinedNot setPrevent interaction and show the disabled state.
shortcutpropstring | undefinedNot setKeyboard shortcut displayed beside this action.
defaultslot{}OptionalContent shown inside ContextMenuRadioItem.
prefixslot{}OptionalContent shown before the main label or value.
suffixslot{}OptionalContent shown after the main label or value.

ContextMenuSeparator

Complete API for ContextMenuSeparator
NameType or signatureDefaultWhat it does

ContextMenuSub

Complete API for ContextMenuSub
NameType or signatureDefaultWhat it does
defaultslot{}OptionalContent shown inside ContextMenuSub.

ContextMenuSubContent

Complete API for ContextMenuSubContent
NameType or signatureDefaultWhat it does
defaultslot{}OptionalContent shown inside ContextMenuSubContent.

ContextMenuSubTrigger

Complete API for ContextMenuSubTrigger
NameType or signatureDefaultWhat it does
defaultslot{}OptionalContent shown inside ContextMenuSubTrigger.
prefixslot{}OptionalContent shown before the main label or value.
suffixslot{}OptionalContent shown after the main label or value.

ContextMenuTrigger

Complete API for ContextMenuTrigger
NameType or signatureDefaultWhat it does
aspropstring | Component | undefined"div"Choose the HTML element or Vue component used for this control.
asChildpropboolean | undefinedNot setUse one child element as the control instead of adding another wrapper.
disabledpropboolean | undefinedNot setPrevent interaction and show the disabled state.
defaultslot{}OptionalContent shown inside ContextMenuTrigger.
Public type definitions
Public types
// packages/frameworks/vue/components/context-menu/types.ts
import type { Component } from 'vue'
import type { DropdownMenuAction } from '../dropdown-menu/types'

export interface ContextMenuTriggerProps {
  as?: string | Component
  asChild?: boolean
  disabled?: boolean
}

export interface ContextMenuProps {
  open?: boolean
  defaultOpen?: boolean
  disabled?: boolean
  width?: number
  gap?: number
  dir?: 'ltr' | 'rtl'
  longPressDelay?: number
}

export type ContextMenuAction = DropdownMenuAction


// packages/frameworks/vue/components/dropdown-menu/types.ts
// ------- TYPES -------

export interface DropdownMenuAction {
  id: string
  label: string
  disabled?: boolean
  destructive?: boolean
  shortcut?: string
  kind?: 'item' | 'checkbox' | 'radio'
  checked?: boolean
  value?: string
}

export type DropdownMenuDataItem = Omit<DropdownMenuAction, 'kind' | 'checked' | 'value'> & {
  kind?: 'item'
}

export type DropdownMenuItem = DropdownMenuDataItem | { id: string; kind: 'separator' }

export interface DropdownMenuProps {
  items?: readonly DropdownMenuItem[]
  label?: string
  open?: boolean
  defaultOpen?: boolean
  disabled?: boolean
  width?: number
  gap?: number
  align?: 'start' | 'center' | 'end'
  side?: 'top' | 'bottom'
  dir?: 'ltr' | 'rtl'
}

export interface DropdownMenuTriggerProps {
  asChild?: boolean
}

export interface DropdownMenuContentProps {
  arrow?: boolean
}

export interface DropdownMenuCheckboxItemProps {
  id: string
  label: string
  checked?: boolean
  disabled?: boolean
  destructive?: boolean
  shortcut?: string
}

export interface DropdownMenuRadioGroupProps {
  modelValue?: string
  defaultValue?: string
}

export interface DropdownMenuRadioItemProps {
  id: string
  value: string
  label: string
  disabled?: boolean
  shortcut?: string
}

export interface DropdownMenuSubProps {
  open?: boolean
  defaultOpen?: boolean
  disabled?: boolean
}

Implementation notes

  • The Context Menu key and Shift+F10 open at the focused trigger; pointer opening uses its interaction point.
  • Menu selection emits an action for the application to execute.

Accessibility and localization

  • Make a custom trigger keyboard-focusable, and provide an ordinary visible route to important actions.
  • Localize the menu name, item labels, and any displayed shortcut hints.

Source contract and editing guidance