Skip to main content

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 card
  • edit - when true, opens the editor on the new card immediately
  • id - explicit ID for the new card (overrides card.id; defaults to a temporary ID)
  • before - ID of an existing card; the new card is inserted before it. null appends to the end. Wins over after.
  • after - ID of an existing card; the new card is inserted after it. Ignored when before is set.

Without either hint, the card goes to the end of its column.

Placement normalization:

  • With only after, before becomes the next card of the destination column in source order, or null when there's none. Filtering, sorting, and swimlanes don't affect this. An unknown after appends.
  • A non-null before or after anchor must belong to the destination column. Otherwise, the action is rejected and doesn't reach on handlers or component handlers.
  • Interceptors see the original hints. After dispatch, the payload carries the canonical before, the inserted id, and the inserted card data (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)} />