CardActionMenu
Menu wrapper that opens when a card's ⋯ button is clicked. Wrap <Kanban> in <CardActionMenu> and enable the button with card.menu: true, or render CardMenuButton inside a custom cardContent. The menu context is the clicked KanbanCard; the default items come from getMenuOptions().
The wrapper needs the kanban api and stays closed until api is set. Without an outer CardActionMenu, the ⋯ buttons do nothing.
Usage
import { CardActionMenu } from "@svar-ui/react-kanban";
Props
Props follow the shared KanbanMenuProps<KanbanCard> type.
| Prop | Type | Default | Description |
|---|---|---|---|
api | KanbanInstanceApi | null | null | Kanban instance used to resolve the card and run built-in actions. |
options | any[] | ((card: KanbanCard) => any[] | null | undefined | false) | getMenuOptions() | Menu items, or a function called on every open. An empty result keeps the menu closed. |
resolver | ((card: KanbanCard, ev: MouseEvent) => any) | null | null | Gate called after the card is resolved. Return a falsy value to keep the menu closed. |
filter | ((item: any, card: KanbanCard) => boolean) | null | null | Per-item 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 }. |
at | string | "point" | Menu placement, forwarded to the menu. |
css | string | - | Extra CSS class forwarded to the menu. |
children | ReactNode | - | Wrapped content - <Kanban> or another menu wrapper. |
onClick doesn't fire when the menu closes without a choice (outside click, Escape).
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 | Dispatches |
|---|---|
edit-card | select-card with card id |
duplicate-card | duplicate-card with card id |
delete-card | delete-card with card id |
Built-in items run before onClick. Other item IDs reach only onClick.
Example
Menu on the ⋯ button with a custom item:
import { useState } from "react";
import {
Kanban,
CardActionMenu,
Editor,
getMenuOptions,
} from "@svar-ui/react-kanban";
const options = [
...getMenuOptions(),
{ id: "my-action", text: "My action", icon: "wxi-empty" },
];
function onClick({ action, context }) {
if (action.id === "my-action") console.log("Card:", context.id);
}
function App() {
const [api, setApi] = useState();
return (
<>
<CardActionMenu api={api} options={options} onClick={onClick}>
<Kanban
init={setApi}
cards={cards}
columns={columns}
card={{ menu: true }}
/>
</CardActionMenu>
{api && <Editor api={api} />}
</>
);
}
The same menu on the button and on right click:
<CardContextMenu api={api} options={options} onClick={onClick}>
<CardActionMenu api={api} options={options} onClick={onClick}>
<Kanban init={setApi} cards={cards} columns={columns} card={{ menu: true }} />
</CardActionMenu>
</CardContextMenu>
Related
- Menu guide - card and column menus, custom items
- CardContextMenu - card menu on right click
- CardMenuButton -
⋯button for a custom card body - getMenuOptions - default card menu items
- card - enable the
⋯button viacard.menu