Skip to main content

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.

PropTypeDefaultDescription
apiKanbanInstanceApi | nullnullKanban instance used to resolve the card and run built-in actions.
optionsany[] | ((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) | nullnullGate called after the card is resolved. Return a falsy value to keep the menu closed.
filter((item: any, card: KanbanCard) => boolean) | nullnullPer-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 }.
atstring"point"Menu placement, forwarded to the menu.
cssstring-Extra CSS class forwarded to the menu.
childrenReactNode-Wrapped content - <Kanban> or another menu wrapper.

onClick doesn't fire when the menu closes without a choice (outside click, Escape).

Methods​

MethodSignatureDescription
showshow(ev: Event, obj?: any)Opens the menu programmatically; obj is the target card ID.

Built-in item IDs​

IDDispatches
edit-cardselect-card with card id
duplicate-cardduplicate-card with card id
delete-carddelete-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>