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/react-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.
childrenReactNode-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:

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

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

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

export default App;

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

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

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

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

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

export default App;