Skip to main content

CardActionMenu

Menu wrapper that opens when a card's ⋯ button is clicked. Wrap <Kanban> in <CardActionMenu> and enable the button with card.menu: true, or render CardMenuButton inside a custom cardContent. The menu context is the clicked KanbanCard; the default items come from getMenuOptions().

The wrapper needs the kanban api and stays closed until api is set. Without an outer CardActionMenu, the ⋯ buttons do nothing.

Usage​

import { CardActionMenu } from "@svar-ui/svelte-kanban";

Props​

Props follow the shared KanbanMenuProps<KanbanCard> type.

PropTypeDefaultDescription
apiKanbanInstanceApi | nullnullKanban instance used to resolve the card and run built-in actions.
optionsany[] | ((card: KanbanCard) => any[] | null | undefined | false)getMenuOptions()Menu items, or a function called on every open. An empty result keeps the menu closed.
resolver((card: KanbanCard, ev: MouseEvent) => any) | nullnullGate called after the card is resolved. Return a falsy value to keep the menu closed.
filter((item: any, card: KanbanCard) => boolean) | nullnullPer-item 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 }.
atstring"point"Menu placement, forwarded to the menu.
cssstring-Extra CSS class forwarded to the menu.
childrenSnippet-Wrapped content - <Kanban> or another menu wrapper.

onclick doesn't fire when the menu closes without a choice (outside click, Escape).

Methods​

MethodSignatureDescription
showshow(ev: Event, obj?: any)Opens the menu programmatically; obj is the target card ID.

Built-in item IDs​

IDDispatches
edit-cardselect-card with card id
duplicate-cardduplicate-card with card id
delete-carddelete-card with card id

Built-in items run before onclick. Other item IDs reach only onclick.

Example​

Menu on the ⋯ button with a custom item:

<script>
import {
Kanban,
CardActionMenu,
Editor,
getMenuOptions,
} from "@svar-ui/svelte-kanban";

let api = $state();

const options = [
...getMenuOptions(),
{ id: "my-action", text: "My action", icon: "wxi-empty" },
];

function onclick({ action, context }) {
if (action.id === "my-action") console.log("Card:", context.id);
}
</script>

<CardActionMenu {api} {options} {onclick}>
<Kanban bind:this={api} {cards} {columns} card={{ menu: true }} />
</CardActionMenu>
{#if api}<Editor {api} />{/if}

The same menu on the button and on right click:

<CardContextMenu {api} {options} {onclick}>
<CardActionMenu {api} {options} {onclick}>
<Kanban bind:this={api} {cards} {columns} card={{ menu: true }} />
</CardActionMenu>
</CardContextMenu>