Skip to main content

CardContextMenu

Wrapper component that opens a card menu when the user right-clicks a card. Put it around <Kanban> to get Edit, Duplicate, and Delete on right click without extra configuration. The menu also supports custom items and can be blocked for specific cards.

The wrapper finds the clicked card from its data-id attribute. The menu context is the card object (KanbanCard). The wrapper has the same props, method, and built-in items as CardActionMenu. CardActionMenu opens on the card ⋯ button, and CardContextMenu opens on right click. Nest the two wrappers to support both.

ContextMenu is a deprecated alias of CardContextMenu.

Usage​

import { CardContextMenu } from "@svar-ui/vue-kanban";

Props​

PropTypeDefaultDescription
apiKanbanInstanceApi | nullnullKanban instance used to find the card and run built-in actions. The menu doesn't open until it is set.
optionsany[] | ((card: KanbanCard) => any[] | null | undefined | false)defaultsMenu items, or a function called each time the menu opens. When omitted, uses getMenuOptions(). An empty result keeps the menu closed.
resolver((card: KanbanCard, ev: MouseEvent) => any) | nullnullGate called after the card is found. Return a falsy value to keep the menu closed for that card.
filter((item: any, card: KanbanCard) => boolean) | nullnullPer-item filter. Return false to hide an item for the current card.
onclick(ev: any) => voidundefinedCalled after built-in handling when the user selects an item. ev.action is the item, ev.context is the card.
atstring"point"Menu placement. "point" opens the menu at the pointer.
cssstringundefinedExtra CSS class for the menu.
childrenSlot-Wrapped content: <Kanban> or another menu wrapper.

The wrapper reads menu labels from a <Locale> around it. Without one, the labels are in English.

The wrapper ignores the readonly prop of <Kanban>. To disable the menu on a readonly board, leave out the wrapper or use resolver.

Methods​

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

Built-in item IDs​

IDTextDispatches
edit-cardEdit cardselect-card with card id
duplicate-cardDuplicate cardduplicate-card with card id
delete-cardDelete carddelete-card with card id

Built-in items run their action before onclick. Items with other IDs only reach onclick.

Example​

Default right-click menu:

<script setup>
import { ref } from "vue";
import { Kanban, Editor, CardContextMenu } from "@svar-ui/vue-kanban";

const api = ref();
</script>

<template>
<CardContextMenu :api="api">
<Kanban ref="api" :cards="cards" :columns="columns" />
</CardContextMenu>
<Editor v-if="api" :api="api" />
</template>

Custom item:

<script setup>
import { ref } from "vue";
import { Kanban, CardContextMenu, getMenuOptions } from "@svar-ui/vue-kanban";

const api = ref();
const options = [
...getMenuOptions(),
{ id: "archive", text: "Archive", icon: "wxi-empty" },
];

function onclick({ action, context }) {
if (action.id === "archive") {
api.value.exec("update-card", { id: context.id, card: { archived: true } });
}
}
</script>

<template>
<CardContextMenu :api="api" :options="options" :onclick="onclick">
<Kanban ref="api" :cards="cards" :columns="columns" />
</CardContextMenu>
</template>

Gated menu: no menu on read-only cards, no Delete on locked cards:

<template>
<CardContextMenu
:api="api"
:resolver="card => !card.readOnly"
:filter="(item, card) => !(card.locked && item.id === 'delete-card')"
>
<Kanban ref="api" :cards="cards" :columns="columns" />
</CardContextMenu>
</template>