Kanban board
Columns of draggable cards with keyboard moves, animated travel between columns and a lifted drag overlay. Adapted from Kibo UI (MIT).
onDataChange receives every preview while a card is over another column; onCommit is called once per completed drop and is where to save. Change data yourself (a button, a menu, a live update) and the card glides to its new column; with reduced motion it fades in there instead. The board is as wide as its columns, so put it in a container that scrolls sideways.
Board
Write the migration guide
Fix the export time zone
Add keyboard shortcuts to the editor
Review the pricing page copy
Confirm the launch date
Nothing has moved yet.
"use client"
import { useState } from "react"
import { KanbanBoard, KanbanCard, KanbanCards, KanbanHeader, KanbanProvider } from "@/components/ui/kanban-board"
const columns = [
{ id: "todo", name: "To do" },
{ id: "doing", name: "In progress" },
{ id: "done", name: "Done" },
]
const tasks = [
{ id: "t1", name: "Write the migration guide", column: "todo" },
{ id: "t2", name: "Fix the export time zone", column: "todo" },
{ id: "t3", name: "Add keyboard shortcuts to the editor", column: "doing" },
{ id: "t4", name: "Review the pricing page copy", column: "doing" },
{ id: "t5", name: "Confirm the launch date", column: "done" },
]
export default function KanbanBoardBasic() {
const [data, setData] = useState(tasks)
const [saved, setSaved] = useState("Nothing has moved yet.")
return (
<div className="flex w-full min-w-0 flex-col gap-4">
<div className="overflow-x-auto">
<KanbanProvider
columns={columns}
data={data}
onDataChange={setData}
// Called once per completed drop: the place to persist the new order.
onCommit={(next, movedId, via) => {
const moved = next.find((task) => task.id === movedId)
const column = columns.find((candidate) => candidate.id === moved?.column)
setSaved(`Saved: ${moved?.name} is in ${column?.name}, moved with the ${via}.`)
}}
>
{(column) => (
<KanbanBoard key={column.id} id={column.id} header={<KanbanHeader>{column.name}</KanbanHeader>}>
<KanbanCards id={column.id}>
{(task) => <KanbanCard key={task.id} id={task.id} name={task.name} />}
</KanbanCards>
</KanbanBoard>
)}
</KanbanProvider>
</div>
<p className="text-sm text-muted-foreground">{saved}</p>
</div>
)
}
Card content
INV-1043
Orchard API€9,100
INV-1042
Atlas redesign€4,800
INV-1041
Billing migration€12,250
No paid invoices
"use client"
import { useState } from "react"
import { Badge } from "@/components/ui/badge"
import { KanbanBoard, KanbanCard, KanbanCards, KanbanHeader, KanbanProvider } from "@/components/ui/kanban-board"
type Invoice = { id: string; name: string; column: string; project: string; amount: string }
const columns = [
{ id: "draft", name: "Draft", tone: "neutral" },
{ id: "issued", name: "Issued", tone: "info" },
{ id: "paid", name: "Paid", tone: "positive" },
] as const
const invoices: Invoice[] = [
{ id: "i1", name: "INV-1043", column: "draft", project: "Orchard API", amount: "€9,100" },
{ id: "i2", name: "INV-1042", column: "issued", project: "Atlas redesign", amount: "€4,800" },
{ id: "i3", name: "INV-1041", column: "issued", project: "Billing migration", amount: "€12,250" },
]
export default function KanbanBoardCardContent() {
const [data, setData] = useState(invoices)
return (
<div className="w-full min-w-0 overflow-x-auto">
<KanbanProvider columns={[...columns]} data={data} onDataChange={setData} onCommit={setData}>
{(column) => (
<KanbanBoard
key={column.id}
id={column.id}
header={
<KanbanHeader>
<Badge variant={column.tone}>{column.name}</Badge>
<span className="text-muted-foreground tabular-nums">
{data.filter((invoice) => invoice.column === column.id).length}
</span>
</KanbanHeader>
}
>
<KanbanCards
id={column.id}
empty={<p className="p-3 text-sm text-muted-foreground">No {column.name.toLowerCase()} invoices</p>}
>
{(invoice: Invoice) => (
<KanbanCard key={invoice.id} id={invoice.id} name={invoice.name}>
<div className="flex flex-col gap-1 p-3">
<p className="font-medium">{invoice.name}</p>
<p className="flex justify-between gap-2 text-sm text-muted-foreground">
{invoice.project}
<span className="tabular-nums">{invoice.amount}</span>
</p>
</div>
</KanbanCard>
)}
</KanbanCards>
</KanbanBoard>
)}
</KanbanProvider>
</div>
)
}
Moved by a button
Freeze the release branch
Publish the release notes
Run the database migration
"use client"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { KanbanBoard, KanbanCard, KanbanCards, KanbanHeader, KanbanProvider } from "@/components/ui/kanban-board"
const columns = [
{ id: "todo", name: "To do", next: "doing", action: "Start" },
{ id: "doing", name: "In progress", next: "done", action: "Finish" },
{ id: "done", name: "Done", next: "todo", action: "Reopen" },
]
const tasks = [
{ id: "t1", name: "Freeze the release branch", column: "todo" },
{ id: "t2", name: "Publish the release notes", column: "todo" },
{ id: "t3", name: "Run the database migration", column: "doing" },
]
export default function KanbanBoardMovedByAButton() {
const [data, setData] = useState(tasks)
const [moved, setMoved] = useState("")
return (
<div className="w-full min-w-0 overflow-x-auto">
<KanbanProvider columns={columns} data={data} onDataChange={setData} onCommit={setData}>
{(column) => (
<KanbanBoard key={column.id} id={column.id} header={<KanbanHeader>{column.name}</KanbanHeader>}>
<KanbanCards id={column.id}>
{(task) => (
<KanbanCard key={task.id} id={task.id} name={task.name}>
<div className="flex flex-col items-start gap-2 p-3">
<p>{task.name}</p>
{/* A control inside a card keeps its own press. The card is drawn again in its new
column, so the button takes focus back there. */}
<Button
size="sm"
variant="outline"
aria-label={`${column.action} ${task.name}`}
autoFocus={task.id === moved}
onFocus={() => setMoved("")}
onClick={() => {
setMoved(task.id)
setData(data.map((item) => (item.id === task.id ? { ...item, column: column.next } : item)))
}}
>
{column.action}
</Button>
</div>
</KanbanCard>
)}
</KanbanCards>
</KanbanBoard>
)}
</KanbanProvider>
</div>
)
}
List rows
To do
In progress
Done
"use client"
import { useState } from "react"
import { KanbanCard, KanbanCards, KanbanGroup, KanbanProvider } from "@/components/ui/kanban-board"
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select"
const columns = [
{ id: "todo", name: "To do" },
{ id: "doing", name: "In progress" },
{ id: "done", name: "Done" },
]
const tasks = [
{ id: "t1", name: "Write the migration guide", column: "todo" },
{ id: "t2", name: "Fix the export time zone", column: "todo" },
{ id: "t3", name: "Review the pricing page copy", column: "doing" },
]
export default function KanbanBoardListRows() {
const [data, setData] = useState(tasks)
const [moved, setMoved] = useState("")
return (
<KanbanProvider
columns={columns}
data={data}
onDataChange={setData}
onCommit={setData}
className="w-full max-w-md flex-col items-stretch gap-4"
>
{(column) => (
<KanbanGroup key={column.id} id={column.id} className="rounded-xl data-target:bg-secondary">
<h3 className="px-3 py-2 text-sm text-muted-foreground">{column.name}</h3>
<KanbanCards id={column.id} role="none" animated={false} className="min-h-10 gap-0">
{(task) => (
<KanbanCard key={task.id} id={task.id} name={task.name} variant="row">
<div className="flex items-center justify-between gap-3 px-3 py-1.5">
{task.name}
{/* A row has no move button: this select is its keyboard path. The row is drawn
again in its new group, so the select takes focus back there. */}
<NativeSelect
className="shrink-0"
aria-label={`Status of ${task.name}`}
value={task.column}
autoFocus={task.id === moved}
onFocus={() => setMoved("")}
onChange={(event) => {
setMoved(task.id)
setData(data.map((item) => (item.id === task.id ? { ...item, column: event.target.value } : item)))
}}
>
{columns.map((option) => (
<NativeSelectOption key={option.id} value={option.id}>
{option.name}
</NativeSelectOption>
))}
</NativeSelect>
</div>
</KanbanCard>
)}
</KanbanCards>
</KanbanGroup>
)}
</KanbanProvider>
)
}
Disabled
4.3.0: shared views
4.2.0: offline drafts
4.1.2: faster search
"use client"
import { KanbanBoard, KanbanCard, KanbanCards, KanbanHeader, KanbanProvider } from "@/components/ui/kanban-board"
const columns = [
{ id: "planned", name: "Planned" },
{ id: "shipped", name: "Shipped" },
]
const releases = [
{ id: "r1", name: "4.3.0: shared views", column: "planned" },
{ id: "r2", name: "4.2.0: offline drafts", column: "shipped" },
{ id: "r3", name: "4.1.2: faster search", column: "shipped" },
]
export default function KanbanBoardDisabled() {
return (
// A disabled board has no tab stop of its own, so the scrolling container takes focus for the arrow keys.
<div role="region" aria-label="Releases" tabIndex={0} className="w-full min-w-0 overflow-x-auto">
<KanbanProvider columns={columns} data={releases} disabled onDataChange={() => {}} onCommit={() => {}}>
{(column) => (
<KanbanBoard key={column.id} id={column.id} header={<KanbanHeader>{column.name}</KanbanHeader>}>
<KanbanCards id={column.id}>
{(release) => <KanbanCard key={release.id} id={release.id} name={release.name} />}
</KanbanCards>
</KanbanBoard>
)}
</KanbanProvider>
</div>
)
}
Installation
npx shadcn@latest add @khaeli/kanban-boardbunx --bun shadcn@latest add @khaeli/kanban-boardInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
- npm packages
- @dnd-kit/core ^6.3.1
- @dnd-kit/sortable ^10.0.0
- @dnd-kit/utilities ^3.2.2
- motion ^12.23.12
- tunnel-rat ^0.1.2
Keyboard
Tab- Moves to each card's move button, named Move and the card's name. It draws as the card's focus ring. Controls inside a card are tab stops of their own, after it.
SpaceEnter- Lift the focused card, and drop it where it is. The button's description says how: press space to pick up, the arrow keys to move, space again to drop, escape to cancel. A lifted card is read out as being over itself, a drop as Move completed, and focus returns to the card. Tab while a card is lifted drops it too.
ArrowLeftArrowRightArrowUpArrowDown- While lifted: move the card to the nearest card or column in that direction, and read out what it is over. A press can land on a neighbour in the same column first, so the next column takes one to three presses; an arrow up or down at the end of a column can cross to the next one too. The card moves to another column at once and takes its place inside a column on the drop.
Escape- While lifted: puts the card back where it was. Read out as Move cancelled.
Accessible name
nameonKanbanCardis required: it names the move button and is what the announcements say, even whenchildrendraw the card.nameon each column is what a move is read out as being over. Put the same text in theKanbanHeader.- Rows (
variant="row") have no move button and cannot be lifted from the keyboard. Give each row a control of its own that changes its column, such as a select, and name it after the row. - With
disabledthe move buttons are disabled: cards cannot be lifted and are not tab stops. - The lifted copy that follows the pointer is hidden from assistive technology.
KanbanCardsis alistof its cards. While a column has no cards it drawsemptyin its place and is not a list, so the text is read as plain content.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/kanban-board.json