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-menuCopy src/lib/ui/ContextMenu.svelte and the dropdown/ folder, with floating.ts, glide.ts, Icon.svelte and tokens.css. No other dependencies.
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
| Prop | Type | Default |
|---|---|---|
label | string (required): names the menu | |
children | Snippet: the thing with the menu | |
menu | Snippet: 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.
| Key | Action |
|---|---|
| Shift F10, Menu | Open the menu. |
| ↓ ↑ | Next / previous item. |
| Enter Space | Choose the item. |
| Esc | Close. |