Skip to main content

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/react-kanban";

Props​

The props are the same as on the other menu wrappers (KanbanMenuProps<ColumnMenuContext>).

PropTypeDefaultDescription
apiKanbanInstanceApi | nullnullKanban instance used to resolve the column and run built-in items. The menu never opens until it's set.
optionsany[] | ((ctx: ColumnMenuContext) => any[] | null | undefined | false)defaultsMenu items, or a function called on every open. An empty result keeps the menu closed.
resolver((ctx: ColumnMenuContext, ev: MouseEvent) => any) | nullnullGate called after the column resolves. 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 the current column.
onClick(ev: any) => voidundefinedFires after built-in handling for a chosen item. Receives { action, context }.
atstring"point"Menu placement mode.
cssstringundefinedExtra CSS class forwarded to the inner menu.
childrenReactNode-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;
};
FieldTypeDescription
columnColumnViewThe projected column: its cards, summaries, collapsed flag, and config fields
cardsKanbanCard[]Cards under the header. In the stack layout, only the cards of that lane
swimlaneSwimlaneViewThe lane of the group header. Set only in the stack layout

Methods​

MethodSignatureDescription
showshow(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​

IDTextDispatches
add-cardAdd cardadd-card into the column (and the lane, in the stack layout) with edit: true, so the editor opens on the new card
collapse-columnCollapse columnupdate-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:

import { useState } from "react";
import { Kanban, ColumnActionMenu } from "@svar-ui/react-kanban";

const columns = [
{ id: "todo", label: "To Do", menu: true },
{ id: "doing", label: "In Progress", menu: true },
{ id: "done", label: "Done", menu: true },
];
const cards = [];

function App() {
const [api, setApi] = useState();

return (
<ColumnActionMenu api={api}>
<Kanban init={setApi} cards={cards} columns={columns} />
</ColumnActionMenu>
);
}

export default App;

Items that follow the column's content. The options function runs on every open, so the "Delete" item shows the current card count:

import { useState } from "react";
import {
Kanban,
ColumnActionMenu,
getColumnMenuOptions,
type ColumnMenuContext,
} from "@svar-ui/react-kanban";

const columns = [
{ id: "todo", label: "To Do", menu: true },
{ id: "done", label: "Done", menu: true },
];
const cards = [];

function App() {
const [api, setApi] = useState<any>();

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.exec("delete-card", { id: c.id }));
}

return (
<ColumnActionMenu api={api} options={options} onClick={onClick}>
<Kanban init={setApi} cards={cards} columns={columns} />
</ColumnActionMenu>
);
}

export default App;