ContextMenu
warning
ContextMenu is deprecated. It's an alias of CardContextMenu, which opens the menu on right click. For the card ⋯ button (card.menu), use CardActionMenu. Both are described in the Card menu guide.
Right-click menu wrapper that resolves the clicked card and dispatches built-in actions. Wrapping <Kanban> in <ContextMenu> adds edit, duplicate, and delete items on right click, with no extra setup. Custom entries and per-card gating are optional.
Usage
import { CardContextMenu } from "@svar-ui/react-kanban";
// deprecated alias:
import { ContextMenu } from "@svar-ui/react-kanban";
Props
Shared KanbanMenuProps of the kanban menu wrappers:
| Prop | Type | Default | Description |
|---|---|---|---|
api | KanbanInstanceApi | null | null | Kanban instance used to resolve the card and run built-in actions. Until it's set, the menu doesn't open. |
options | any[] | ((card: KanbanCard) => any[] | null | undefined | false) | getMenuOptions() | Menu items, or a function called with the card on every open. An empty result keeps the menu closed. |
resolver | ((card: KanbanCard, ev: MouseEvent) => any) | null | null | Gate called after card resolution. Return falsy to suppress the menu for that card. |
filter | ((item: any, card: KanbanCard) => boolean) | null | null | Per-item visibility filter. Return false to hide an item for the current card. |
onClick | (ev: any) => void | - | Fires after built-in handling for a chosen item. Receives { action, context } where action.id is the item id and context is the card. |
at | string | "point" | Menu placement mode. |
css | string | - | Extra CSS class forwarded to the inner menu. |
children | ReactNode | - | Wrapped content, typically <Kanban>. |
Methods
| Method | Signature | Description |
|---|---|---|
show | show(ev: Event, obj?: any) | Opens the menu programmatically; obj is the target card ID. |
Built-in item IDs
| ID | Text | Dispatches |
|---|---|---|
edit-card | Edit card | select-card with card id |
duplicate-card | Duplicate card | duplicate-card with card id |
delete-card | Delete card | delete-card with card id |
Custom item IDs don't auto-dispatch. Handle them in onClick.
Example
Default right-click menu:
const [api, setApi] = useState(null);
<ContextMenu api={api}>
<Kanban init={setApi} cards={cards} columns={columns} />
</ContextMenu>
{api && <Editor api={api} />}
Extended menu with a custom action:
import { Kanban, ContextMenu, getMenuOptions } from "@svar-ui/react-kanban";
const [api, setApi] = useState(null);
const options = [
...getMenuOptions(),
{ id: "archive", text: "Archive", icon: "wxi-empty" },
];
const onClick = ({ action, context }) => {
if (action.id === "archive") {
api.exec("update-card", {
id: context.id,
card: { archived: true },
});
}
};
<ContextMenu api={api} options={options} onClick={onClick}>
<Kanban init={setApi} cards={cards} columns={columns} />
</ContextMenu>
Gated menu - block for read-only cards, hide delete for locked cards:
<ContextMenu
api={api}
resolver={(card) => !card.readOnly}
filter={(item, card) => !(card.locked && item.id === "delete-card")}
>
<Kanban init={setApi} cards={cards} columns={columns} />
</ContextMenu>
Related
- Card menu guide - right-click menu, per-card button, custom items
- getMenuOptions - default menu items
- card -
card.menurenders the⋯button thatCardActionMenuopens on