Skip to content
Navigation Core Stable

ContextMenu

.md

A menu that opens at the pointer on right-click, sharing DropdownMenu's item, submenu and keyboard behaviour but anchored to a virtual point instead of a trigger element.

Available for Svelte 5, React, and Vue 3.

Preview

Installation

pnpm add fancy-ui-svelte
import { ContextMenu } from "fancy-ui-svelte";

Usage

svelte
<script lang="ts">
	import {
		ContextMenu,
		ContextMenuTrigger,
		ContextMenuContent,
		ContextMenuItem,
		ContextMenuSeparator,
	} from "fancy-ui-svelte";
</script>

<ContextMenu sound>
	<ContextMenuTrigger>
		<div
			class="border-border text-muted-foreground flex h-[140px] w-full items-center justify-center rounded-[10px] border border-dashed text-[13px]"
		>
			Right-click here
		</div>
	</ContextMenuTrigger>
	<ContextMenuContent>
		<ContextMenuItem onSelect={() => console.log("back")}>Previous</ContextMenuItem>
		<ContextMenuItem onSelect={() => console.log("forward")}>Next</ContextMenuItem>
		<ContextMenuItem onSelect={() => console.log("reload")}>Reload</ContextMenuItem>
		<ContextMenuSeparator />
		<ContextMenuItem onSelect={() => console.log("save")}>Save page…</ContextMenuItem>
	</ContextMenuContent>
</ContextMenu>

Examples

Basic Usage

With Submenu

A nested submenu inside a context menu, using the same Sub primitives as DropdownMenu.

Disabled Items

Disabled rows are skipped by keyboard navigation and inert to click.

Props

PropTypeDefaultDescription
open booleanfalseWhether the menu is open. Bindable
onOpenChange (open: boolean) => void-Called whenever the menu opens or closes, however it happened
side "top" | "bottom" | "left" | "right""bottom"Side of the pointer to place the menu on. Flips when it would overflow
align "start" | "center" | "end""start"Alignment along the pointer's cross axis
offset number2Gap in pixels between the pointer and the menu
loop booleantrueWhether arrow-key navigation wraps at the ends
sound booleanfalsePlays open/close on the menu and its submenus and select on an item, once the user has enabled sound

Slots

SlotDescription
children The ContextMenuTrigger and ContextMenuContent