ContextMenu
warning
ContextMenu is deprecated. It's an alias of CardContextMenu, which opens the menu on right click. For the card ⋯ button (card.menu), use CardActionMenu. Both are described in the Card menu guide.
Right-click menu wrapper that resolves the clicked card and dispatches built-in actions. Wrapping <Kanban> in <ContextMenu> adds edit, duplicate, and delete items on right click, with no extra setup. Custom entries and per-card gating are optional.
Usage
import { CardContextMenu } from "@svar-ui/svelte-kanban";
// deprecated alias:
import { ContextMenu } from "@svar-ui/svelte-kanban";
Props
Shared KanbanMenuProps of the kanban menu wrappers:
| Prop | Type | Default | Description |
|---|---|---|---|
api | KanbanInstanceApi | null | null | Kanban instance used to resolve the card and run built-in actions. Until it's set, the menu doesn't open. |
options | any[] | ((card: KanbanCard) => any[] | null | undefined | false) | getMenuOptions() | Menu items, or a function called with the card on every open. An empty result keeps the menu closed. |
resolver | ((card: KanbanCard, ev: MouseEvent) => any) | null | null | Gate called after card resolution. Return falsy to suppress the menu for that card. |
filter | ((item: any, card: KanbanCard) => boolean) | null | null | Per-item visibility filter. Return false to hide an item for the current card. |
onclick | (ev: any) => void | - | Fires after built-in handling for a chosen item. Receives { action, context } where action.id is the item id and context is the card. |
at | string | "point" | Menu placement mode. |
css | string | - | Extra CSS class forwarded to the inner menu. |
children | Snippet | - | Wrapped content, typically <Kanban>. |
Methods
| Method | Signature | Description |
|---|---|---|
show | show(ev: Event, obj?: any) | Opens the menu programmatically; obj is the target card ID. |
Built-in item IDs
| ID | Text | Dispatches |
|---|---|---|
edit-card | Edit card | select-card with card id |
duplicate-card | Duplicate card | duplicate-card with card id |
delete-card | Delete card | delete-card with card id |
Custom item IDs don't auto-dispatch. Handle them in onclick.
Example
Default right-click menu:
<ContextMenu {api}>
<Kanban bind:this={api} {cards} {columns} />
</ContextMenu>
{#if api}<Editor {api} />{/if}
Extended menu with a custom action:
<script>
import { Kanban, ContextMenu, getMenuOptions } from "@svar-ui/svelte-kanban";
let api = $state();
const options = [
...getMenuOptions(),
{ id: "archive", text: "Archive", icon: "wxi-empty" },
];
function onclick({ action, context }) {
if (action.id === "archive") {
api.exec("update-card", {
id: context.id,
card: { archived: true },
});
}
}
</script>
<ContextMenu {api} {options} {onclick}>
<Kanban bind:this={api} {cards} {columns} />
</ContextMenu>
Gated menu - block for read-only cards, hide delete for locked cards:
<ContextMenu
{api}
resolver={card => !card.readOnly}
filter={(item, card) => !(card.locked && item.id === "delete-card")}
>
<Kanban bind:this={api} {cards} {columns} />
</ContextMenu>
Related
- Card menu guide - right-click menu, per-card button, custom items
- getMenuOptions - default menu items
- card -
card.menurenders the⋯button thatCardActionMenuopens on