File actions
Offer context-specific commands on a file tile through right-click, keyboard, or long press.
Components / Overlays
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.
bunx --bun @getweini/cli@latest add context-menuImport 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.
<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.
Offer context-specific commands on a file tile through right-click, keyboard, or long press.
Apply commands to the exact item whose trigger opened the menu.
ContextMenuItem uses the installed context-menu child.
<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>Keep the destructive action distinct from ordinary 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 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>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.
| Name | Type or signature | Default | What it does |
|---|---|---|---|
openmodel | boolean | undefined | Not set | Current open state. Use v-model:open to keep it in sync with your page. |
defaultOpenprop | boolean | undefined | Not set | Starting open state when the parent does not control open. |
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
widthprop | number | undefined | 224 | Choose the width of this content. |
gapprop | number | undefined | 0 | Space in pixels between the trigger and floating content. |
dirprop | "ltr" | "rtl" | undefined | "ltr" | Set the text direction used for keyboard and layout behavior. |
longPressDelayprop | number | undefined | 600 | Time 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 | {} | Optional | Content shown inside ContextMenu. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
idprop | string | Required | Give the control an ID so a label or description can refer to it. |
labelprop | string | Required | Visible or accessible name for this item. |
checkedprop | boolean | undefined | Not set | Current checked state of this choice. |
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
destructiveprop | boolean | undefined | Not set | Show that an action has a potentially destructive result. |
shortcutprop | string | undefined | Not set | Keyboard shortcut displayed beside this action. |
defaultslot | {} | Optional | Content shown inside ContextMenuCheckboxItem. |
prefixslot | {} | Optional | Content shown before the main label or value. |
suffixslot | {} | Optional | Content shown after the main label or value. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
defaultslot | {} | Optional | Content shown inside ContextMenuContent. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
defaultslot | {} | Optional | Content shown inside ContextMenuGroup. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
defaultslot | {} | Optional | Content shown inside ContextMenuItem. |
prefixslot | {} | Optional | Content shown before the main label or value. |
suffixslot | {} | Optional | Content shown after the main label or value. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
defaultslot | {} | Optional | Content shown inside ContextMenuLabel. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
defaultslot | {} | Optional | Content shown inside ContextMenuRadioGroup. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
idprop | string | Required | Give the control an ID so a label or description can refer to it. |
valueprop | string | Required | Value represented by this control or option. |
labelprop | string | Required | Visible or accessible name for this item. |
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
shortcutprop | string | undefined | Not set | Keyboard shortcut displayed beside this action. |
defaultslot | {} | Optional | Content shown inside ContextMenuRadioItem. |
prefixslot | {} | Optional | Content shown before the main label or value. |
suffixslot | {} | Optional | Content shown after the main label or value. |
| Name | Type or signature | Default | What it does |
|---|
| Name | Type or signature | Default | What it does |
|---|---|---|---|
defaultslot | {} | Optional | Content shown inside ContextMenuSub. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
defaultslot | {} | Optional | Content shown inside ContextMenuSubContent. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
defaultslot | {} | Optional | Content shown inside ContextMenuSubTrigger. |
prefixslot | {} | Optional | Content shown before the main label or value. |
suffixslot | {} | Optional | Content shown after the main label or value. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
asprop | string | Component | undefined | "div" | Choose the HTML element or Vue component used for this control. |
asChildprop | boolean | undefined | Not set | Use one child element as the control instead of adding another wrapper. |
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
defaultslot | {} | Optional | Content shown inside ContextMenuTrigger. |
// 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
}