ColumnActionMenu
Menu wrapper that opens when the user clicks the ⋯ button in a column header. Wrapping <Kanban> in <ColumnActionMenu> gives each column its own actions, such as adding a card or collapsing the column.
The button is opt-in per column: set menu: true on a ColumnConfig. Columns without it have no button, and a click elsewhere on the header never opens this menu.
Usage
import { ColumnActionMenu } from "@svar-ui/vue-kanban";
Props
The props are the same as on the other menu wrappers (KanbanMenuProps<ColumnMenuContext>).
| Prop | Type | Default | Description |
|---|---|---|---|
api | KanbanInstanceApi | null | null | Kanban instance used to resolve the column and run built-in items. The menu never opens until it's set. |
options | any[] | ((ctx: ColumnMenuContext) => any[] | null | undefined | false) | defaults | Menu items, or a function called on every open. An empty result keeps the menu closed. |
resolver | ((ctx: ColumnMenuContext, ev: MouseEvent) => any) | null | null | Gate called after the column resolves. 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 the current column. |
onclick | (ev: any) => void | undefined | Fires after built-in handling for a chosen item. Receives { action, context }. |
at | string | "point" | Menu placement mode. |
css | string | undefined | Extra CSS class forwarded to the inner menu. |
children | Slot | - | Wrapped content, typically <Kanban> or another menu wrapper. |
onclick doesn't fire when the user closes the menu without choosing an item.
Context
options, resolver, filter, and onclick (as ev.context) receive a ColumnMenuContext:
type ColumnMenuContext = {
column: ColumnView;
cards: KanbanCard[];
swimlane?: SwimlaneView;
};
| Field | Type | Description |
|---|---|---|
column | ColumnView | The projected column: its cards, summaries, collapsed flag, and config fields |
cards | KanbanCard[] | Cards under the header. In the stack layout, only the cards of that lane |
swimlane | SwimlaneView | The lane of the group header. Set only in the stack layout |
Methods
| Method | Signature | Description |
|---|---|---|
show | show(ev: Event, obj?: any) | Opens the menu programmatically; obj is the target column ID. |
Default items
Without options, the menu shows getColumnMenuOptions(), which returns a single add-card item. The menu hides it on columns with addCard: false.
Custom options are used exactly as passed. Code that builds on getColumnMenuOptions() has to filter out add-card for addCard: false columns.
Built-in item IDs
| ID | Text | Dispatches |
|---|---|---|
add-card | Add card | add-card into the column (and the lane, in the stack layout) with edit: true, so the editor opens on the new card |
collapse-column | Collapse column | update-column that toggles the column's collapsed flag |
collapse-column isn't in the defaults. Add { id: "collapse-column", text: "Collapse column" } to options to show it. Item texts are localized through the kanban locale group. Custom item IDs don't auto-dispatch. Handle them in onclick.
Example
Default menu on every column's ⋯ button:
<script setup>
import { ref } from "vue";
import { Kanban, ColumnActionMenu } from "@svar-ui/vue-kanban";
const api = ref();
const columns = [
{ id: "todo", label: "To Do", menu: true },
{ id: "doing", label: "In Progress", menu: true },
{ id: "done", label: "Done", menu: true },
];
const cards = [];
</script>
<template>
<ColumnActionMenu :api="api">
<Kanban ref="api" :cards="cards" :columns="columns" />
</ColumnActionMenu>
</template>
Items that follow the column's content. The options function runs on every open, so the "Delete" item shows the current card count:
<script setup lang="ts">
import { ref } from "vue";
import {
Kanban,
ColumnActionMenu,
getColumnMenuOptions,
type ColumnMenuContext,
} from "@svar-ui/vue-kanban";
const api = ref<any>();
const columns = [
{ id: "todo", label: "To Do", menu: true },
{ id: "done", label: "Done", menu: true },
];
const cards = [];
function options(ctx: ColumnMenuContext) {
const items: any[] = getColumnMenuOptions().filter(
o => o.id !== "add-card" || ctx.column.addCard
);
items.push({ id: "collapse-column", text: "Collapse column" });
if (ctx.cards.length)
items.push({ id: "clear-column", text: `Delete ${ctx.cards.length} card(s)` });
return items;
}
function onclick({ action, context }: any) {
if (action.id === "clear-column")
context.cards.forEach(c => api.value.exec("delete-card", { id: c.id }));
}
</script>
<template>
<ColumnActionMenu :api="api" :options="options" :onclick="onclick">
<Kanban ref="api" :cards="cards" :columns="columns" />
</ColumnActionMenu>
</template>
Related
- Card menu guide - card and column menus, custom items
- columns - enable the header button with
menu: true - ColumnContextMenu - the same column menu on header right click
- getColumnMenuOptions - default column menu items