Skip to main content

ColumnContextMenu

A menu wrapper that opens when the user right-clicks a column header or a collapsed column rail. Wrap <Kanban> in <ColumnContextMenu> to add column actions, such as adding a card or collapsing the column, without a ⋯ button. It takes the same props and runs the same built-in items as ColumnActionMenu. The only difference is how the menu opens.

The menu finds its target through the data-column-id attribute that every column header and collapsed rail carries. Its context is a ColumnMenuContext: the projected column and the cards under that header. In stack layout, a header belongs to one lane, so cards holds only that lane's cards and swimlane is set.

Usage​

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

Props​

PropTypeDefaultDescription
apiKanbanInstanceApi | nullnullKanban instance used to resolve the column and run built-in items. The menu doesn't open until it's set.
optionsany[] | ((ctx: ColumnMenuContext) => any[] | null | undefined | false)defaultsMenu items, or a function called on every open. When omitted, uses getColumnMenuOptions(). An empty result keeps the menu closed.
resolver((ctx: ColumnMenuContext, ev: MouseEvent) => any) | nullnullGate called after the column is resolved. Return a falsy value to keep the menu closed.
filter((item: any, ctx: ColumnMenuContext) => boolean) | nullnullPer-item filter. Return false to hide an item for this column.
onclick(ev: any) => voidundefinedCalled after built-in handling for a chosen item. Receives { action, context }.
atstring"point"Menu placement, forwarded to the inner menu.
cssstringundefinedExtra CSS class forwarded to the inner menu.
defaultSlot-Wrapped content: <Kanban> or another menu wrapper.

ColumnMenuContext:

FieldTypeDescription
columnColumnViewProjected column, with its cards, summaries, dataStatus, collapsed, ...
cardsKanbanCard[]Cards under the header; in stack layout, only one lane's cards
swimlaneSwimlaneViewThe lane of the header; set in stack layout only

Methods​

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

Built-in item IDs​

IDDefault itemDispatches
add-cardyesadd-card with edit: true; the new card gets the column (and lane) through the accessors
collapse-columnnoupdate-column, toggling collapsed

getColumnMenuOptions() returns only add-card. When options is omitted, the menu hides add-card on columns with addCard: false. Custom options are used exactly as given, with no filtering. collapse-column appears only when it's listed in options. Other IDs don't dispatch anything; handle them in onclick.

onclick fires only when the user chooses an item. Closing the menu with an outside click or Escape doesn't call it.

Example​

Default right-click menu on column headers:

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

const api = ref();
</script>

<template>
<ColumnContextMenu :api="api">
<Kanban ref="api" :cards="cards" :columns="columns" />
</ColumnContextMenu>
</template>

Menu that adapts to the column - collapse and a custom "clear" item:

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

const api = ref();

function options(ctx) {
const items = getColumnMenuOptions().filter(
o => o.id !== "add-card" || ctx.column.addCard !== false
);
items.push({ id: "collapse-column", text: "Collapse" });
if (ctx.cards.length)
items.push({ id: "clear-column", text: `Delete ${ctx.cards.length} card(s)` });
return items;
}

function onclick({ action, context }) {
if (action.id === "clear-column")
context.cards.forEach(c => api.value.exec("delete-card", { id: c.id }));
}
</script>

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