Components
Context Menu
Radix context menu triggered by right click or long press.
Installation
$ npx veil-ui@latest add context-menuUsage
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuTrigger,
} from "@/components/ui/context-menu";
<ContextMenu>
<ContextMenuTrigger>Right-click this area</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem>Copy</ContextMenuItem>
<ContextMenuItem>Paste</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>;Examples
Basic
Right-click this area
Shortcuts
Right-click for actions
API reference
Subcomponents
ContextMenu,ContextMenuTrigger,ContextMenuContent— root and trigger area with a portalled panel.ContextMenuItem,ContextMenuLabel,ContextMenuSeparator— entries and grouping.
Accessibility
- Radix also opens the menu with the keyboard context-menu key and handles focus return.
- Give the trigger visible instructions when right-click is not obvious.
- Do not put destructive-only actions here without a confirmation dialog.
Vue and plain HTML
This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add context-menu --framework vue or switch the framework in components.json.
<script setup lang="ts">
import { ContextMenuContent, ContextMenuPortal } from "reka-ui";
import { cn } from "@/lib/utils";
const props = defineProps<{ class?: string }>();
</script>
<template>
<ContextMenuPortal>
<ContextMenuContent
data-slot="context-menu-content"
:class="
cn(
'z-50 min-w-44 rounded-md border bg-popover p-1 text-popover-foreground shadow-md',
'data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=bottom]:slide-out-to-top-2 data-[side=top]:slide-out-to-bottom-2 data-[side=left]:slide-out-to-right-2 data-[side=right]:slide-out-to-left-2 origin-[var(--reka-popper-transform-origin)]',
props.class,
)
"
>
<slot />
</ContextMenuContent>
</ContextMenuPortal>
</template>