Overlays

Context menu

Offers actions for a thing where it is: right-click it, long-press it, or press Shift+F10.

Installation

npx sinaui add context-menu

Examples

Basic

The menu opens at the pointer and flips to stay on screen. Its items are Dropdown items: links or actions, with the same keys.

Kitāb al-Manāẓir Ibn al-Haytham · Book of Optics · 1021
Right-click, long-press or press Shift+F10 for options.

Right-click the card, long-press it, or focus it and press Shift+F10.

<script lang="ts">
	import { Book02Icon, Delete02Icon, Share08Icon, ViewIcon } from '@hugeicons/core-free-icons';
	import ContextMenu from '#lib/ui/ContextMenu.svelte';
	import Icon from '#lib/ui/Icon.svelte';
	import * as Dropdown from '#lib/ui/dropdown/index.js';

	let last = $state<string>();
</script>

<div class="stack">
	<ContextMenu label="Options for Book of Optics">
		<div class="card">
			<strong>Kitāb al-Manāẓir</strong>
			<span>Ibn al-Haytham · Book of Optics · 1021</span>
		</div>
		{#snippet menu()}
			<Dropdown.Item onselect={() => (last = 'Open')}><Icon icon={ViewIcon} /> Open</Dropdown.Item>
			<Dropdown.Item onselect={() => (last = 'Copy link')}
				><Icon icon={Share08Icon} /> Copy link</Dropdown.Item
			>
			<Dropdown.Item onselect={() => (last = 'Move to reading room')}>
				<Icon icon={Book02Icon} /> Move to reading room
			</Dropdown.Item>
			<Dropdown.Separator />
			<Dropdown.Item variant="danger" onselect={() => (last = 'Remove from list')}>
				<Icon icon={Delete02Icon} /> Remove from list
			</Dropdown.Item>
		{/snippet}
	</ContextMenu>
	<p>
		{last
			? `Last action: ${last}`
			: 'Right-click the card, long-press it, or focus it and press Shift+F10.'}
	</p>
</div>

<style>
	.stack {
		display: grid;
		gap: 0.75rem;
		inline-size: min(100%, 24rem);
	}
	.card {
		display: grid;
		gap: 0.125rem;
		padding: 1rem 1.125rem;
		border-radius: var(--ui-radius);
		background: var(--ui-subtle);
	}
	.card span,
	p {
		color: var(--ui-muted);
		font-size: 0.875rem;
	}
	p {
		margin: 0;
	}
</style>

Props

PropTypeDefault
labelstring (required): names the menu
childrenSnippet: the thing with the menu
menuSnippet: Dropdown.Items and Dropdown.Separators

Accessibility

  • The thing can be focused, and screen readers hear how to open its menu.
  • A right-click is a shortcut: keep the same actions reachable another way, like a “More” button.
  • Closing puts focus back on the thing.
KeyAction
Shift F10, MenuOpen the menu.
↓ ↑Next / previous item.
Enter SpaceChoose the item.
EscClose.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme