add-card
Adds a new card to the board. A card without a column (via columnAccessor) goes to the first column. With swimlanes, a missing or invalid lane falls back to the first declared lane. When neither id nor card.id is set, the card gets a temporary ID.
Usage
type AddCardPayload = {
card: Partial<KanbanCard>;
edit?: boolean;
id?: CardID;
before?: CardID | null;
after?: CardID;
};
card- partial card object with the fields to set on the new cardedit- whentrue, opens the editor on the new card immediatelyid- explicit ID for the new card (overridescard.id; defaults to a temporary ID)before- ID of an existing card; the new card is inserted before it.nullappends to the end. Wins overafter.after- ID of an existing card; the new card is inserted after it. Ignored whenbeforeis set.
Without either hint, the card goes to the end of its column.
Placement normalization:
- With only
after,beforebecomes the next card of the destination column in source order, ornullwhen there's none. Filtering, sorting, and swimlanes don't affect this. An unknownafterappends. - A non-null
beforeorafteranchor must belong to the destination column. Otherwise, the action is rejected and doesn't reachonhandlers or component handlers. - Interceptors see the original hints. After dispatch, the payload carries the canonical
before, the insertedid, and the insertedcarddata (with column and lane defaults applied).
Trigger
api.exec("add-card", {
card: { label: "New task" },
edit: true,
});
Observe
api.on("add-card", ev => {
console.log("Card added with id:", ev.id);
});
Intercept
api.intercept("add-card", ev => {
if (!ev.card.label) return false; // cancel if no label
});
Component handler
<Kanban :onaddcard="(ev) => console.log('added:', ev.id)" />
Related
- Cards guide - adding, updating, and managing cards
- duplicate-card - clone an existing card
- select-card - open the editor on the new card
- exec - how to dispatch actions