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
| Prop | Type | Default | Description |
|---|---|---|---|
api | KanbanInstanceApi | null | null | Kanban instance used to resolve the column and run built-in items. The menu doesn't open until it's set. |
options | any[] | ((ctx: ColumnMenuContext) => any[] | null | undefined | false) | defaults | Menu 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) | null | null | Gate called after the column is resolved. Return a falsy value to keep the menu closed. |
filter | ((item: any, ctx: ColumnMenuContext) => boolean) | null | null | Per-item filter. Return false to hide an item for this column. |
onclick | (ev: any) => void | undefined | Called after built-in handling for a chosen item. Receives { action, context }. |
at | string | "point" | Menu placement, forwarded to the inner menu. |
css | string | undefined | Extra CSS class forwarded to the inner menu. |
default | Slot | - | Wrapped content: <Kanban> or another menu wrapper. |
ColumnMenuContext:
| Field | Type | Description |
|---|---|---|
column | ColumnView | Projected column, with its cards, summaries, dataStatus, collapsed, ... |
cards | KanbanCard[] | Cards under the header; in stack layout, only one lane's cards |
swimlane | SwimlaneView | The lane of the header; set in stack layout only |
Methods
| Method | Signature | Description |
|---|---|---|
show | show(ev: Event, obj?: any) | Opens the menu programmatically; obj is the target column ID. |
Built-in item IDs
| ID | Default item | Dispatches |
|---|---|---|
add-card | yes | add-card with edit: true; the new card gets the column (and lane) through the accessors |
collapse-column | no | update-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>
Related
- Menus guide - card and column menus, nesting, custom items
- ColumnActionMenu - the same menu opened from the column
⋯button - getColumnMenuOptions - default column menu items