# Kanban board

A sprint board with four columns and their counts, a work-in-progress limit that warns when a column runs over, and cards with labels as `Badge`s, assignee avatars, due dates and comment counts. Each card’s `Menu` moves it to another column, so the board works by keyboard without a drag library.

**Example: Sprint 14** (`examples/recipes/kanban-board.tsx`)

```tsx
'use client'

import { Badge, BodySmall, Button, Heading, Menu, Stack, Text, toastSuccess } from '@blocks/design-system'
import { AlertTriangle, ArrowRight, CalendarDays, MessageSquare, MoreHorizontal } from 'lucide-react'
import { useEffect, useId, useRef, useState } from 'react'
import styles from './kanban-board.module.css'

type ColumnId = 'backlog' | 'progress' | 'review' | 'done'

const columns: { id: ColumnId; title: string; limit?: number }[] = [
  { id: 'backlog', title: 'Backlog' },
  { id: 'progress', title: 'In progress', limit: 3 },
  { id: 'review', title: 'Review', limit: 3 },
  { id: 'done', title: 'Done' },
]

interface Task {
  key: string
  title: string
  column: ColumnId
  labels: string[]
  assignees: string[]
  /** ISO date; the board is viewed on December 2, 2026. */
  due?: string
  comments: number
}

const today = '2026-12-02'
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
const shortDate = (iso: string) => `${months[Number(iso.slice(5, 7)) - 1]} ${Number(iso.slice(8))}`

const initialTasks: Task[] = [
  { key: 'FERN-212', title: 'Export reports as CSV', column: 'backlog', labels: ['Feature'], assignees: [], due: '2026-12-18', comments: 2 },
  { key: 'FERN-219', title: 'Audit color contrast in charts', column: 'backlog', labels: ['Accessibility'], assignees: ['Ama Mensah'], due: '2026-12-11', comments: 0 },
  { key: 'FERN-221', title: 'Rate-limit password resets', column: 'backlog', labels: ['Security'], assignees: ['Marcus Oyelaran'], comments: 1 },
  {
    key: 'FERN-198',
    title: 'Offline drafts sync',
    column: 'progress',
    labels: ['Feature', 'Mobile'],
    assignees: ['Priya Natarajan', 'Tomás Oliveira'],
    due: '2026-12-04',
    comments: 7,
  },
  { key: 'FERN-204', title: 'Crash when rotating during upload', column: 'progress', labels: ['Bug', 'Mobile'], assignees: ['Ama Mensah'], due: '2026-11-30', comments: 4 },
  { key: 'FERN-207', title: 'Onboarding checklist copy', column: 'progress', labels: ['Content'], assignees: ['Hannah Kim'], due: '2026-12-09', comments: 2 },
  { key: 'FERN-210', title: 'Move webhooks to queue v2', column: 'progress', labels: ['Infrastructure'], assignees: ['Marcus Oyelaran'], due: '2026-12-15', comments: 3 },
  { key: 'FERN-195', title: 'Accessible labels for the composer', column: 'review', labels: ['Accessibility'], assignees: ['Hannah Kim'], due: '2026-12-03', comments: 5 },
  { key: 'FERN-188', title: 'Search ignores accented characters', column: 'done', labels: ['Bug'], assignees: ['Ama Mensah'], comments: 6 },
  { key: 'FERN-190', title: 'Dark mode for settings', column: 'done', labels: ['Design'], assignees: ['Priya Natarajan'], comments: 2 },
]

function initials(name: string) {
  return name
    .split(' ')
    .map((part) => part[0])
    .join('')
}

export default function KanbanBoard() {
  const [tasks, setTasks] = useState(initialTasks)
  const [moved, setMoved] = useState<string | null>(null)
  const menuTriggers = useRef(new Map<string, HTMLButtonElement>())
  const id = useId()

  // A moved card re-renders in another column, so focus follows it there.
  useEffect(() => {
    if (moved) menuTriggers.current.get(moved)?.focus()
  }, [moved])

  function move(task: Task, column: ColumnId) {
    setTasks((current) => [...current.filter((item) => item.key !== task.key), { ...task, column }])
    setMoved(task.key)
    toastSuccess(`Moved ${task.key} to ${columns.find((item) => item.id === column)?.title}`)
  }

  return (
    <Stack as="section" gap="md" aria-labelledby={`${id}-board`} dangerouslySetClassName={styles.kanban}>
      <Stack direction="row" justify="space-between" align="baseline" wrap="wrap" gap="sm">
        <Heading as="h2" id={`${id}-board`} fontSize="xl">
          Sprint 14
        </Heading>
        <BodySmall color="text-muted" margin="none">
          Tidewater mobile · ends Dec 11
        </BodySmall>
      </Stack>
      {/* biome-ignore lint/a11y/noNoninteractiveTabindex: a scrolling region must be reachable by keyboard */}
      <section className={styles.board} aria-label="Board columns, scrolls sideways" tabIndex={0}>
        {columns.map((column) => {
          const columnTasks = tasks.filter((task) => task.column === column.id)
          const overLimit = column.limit !== undefined && columnTasks.length > column.limit
          return (
            <section key={column.id} className={styles.column} aria-labelledby={`${id}-${column.id}`} data-over-limit={overLimit || undefined}>
              <Stack direction="row" justify="space-between" align="center" gap="sm" paddingX="sm">
                <Heading as="h3" id={`${id}-${column.id}`} fontSize="sm">
                  {column.title}
                </Heading>
                <Text fontSize="xs" color={overLimit ? 'warning-text' : 'text-muted'} dangerouslySetClassName={styles.count}>
                  {columnTasks.length}
                  {column.limit !== undefined && ` / ${column.limit}`}
                  <span className="visually-hidden">{column.limit === undefined ? ' cards' : ` cards, limit ${column.limit}`}</span>
                </Text>
              </Stack>
              {overLimit && (
                <Text fontSize="xs" color="warning-text" dangerouslySetClassName={styles.warning}>
                  <AlertTriangle aria-hidden size={12} />
                  Over the work-in-progress limit
                </Text>
              )}
              <ul className={styles.cards}>
                {columnTasks.map((task) => {
                  const overdue = task.due !== undefined && task.due < today && task.column !== 'done'
                  return (
                    <li key={task.key}>
                      <article className={styles.card} aria-labelledby={`${id}-${task.key}`}>
                        <Stack direction="row" justify="space-between" align="start" gap="sm">
                          <Stack gap="xxs">
                            <Text fontSize="xs" color="text-muted" fontFamily="monospace">
                              {task.key}
                            </Text>
                            <Heading as="h4" id={`${id}-${task.key}`} fontSize="sm" fontWeight="semibold" lineHeight="body">
                              {task.title}
                            </Heading>
                          </Stack>
                          <Menu>
                            <Menu.Trigger
                              ref={(node: HTMLButtonElement | null) => {
                                if (node) menuTriggers.current.set(task.key, node)
                                else menuTriggers.current.delete(task.key)
                              }}
                              render={<Button type="button" size="sm" variant="ghost" aria-label={`Actions for ${task.key}`} dangerouslySetClassName={styles.iconButton} />}
                            >
                              <MoreHorizontal aria-hidden size={16} />
                            </Menu.Trigger>
                            <Menu.Content align="end">
                              <Menu.Group>
                                <Menu.GroupLabel>Move to</Menu.GroupLabel>
                                {columns
                                  .filter((item) => item.id !== task.column)
                                  .map((item) => (
                                    <Menu.Item key={item.id} onClick={() => move(task, item.id)}>
                                      <ArrowRight aria-hidden size={14} />
                                      {item.title}
                                    </Menu.Item>
                                  ))}
                              </Menu.Group>
                              <Menu.Separator />
                              <Menu.LinkItem href={`#task-${task.key.toLowerCase()}`}>Open task</Menu.LinkItem>
                            </Menu.Content>
                          </Menu>
                        </Stack>
                        <Stack direction="row" gap="xs" wrap="wrap">
                          {task.labels.map((label) => (
                            <Badge key={label}>{label}</Badge>
                          ))}
                        </Stack>
                        <div className={styles.meta}>
                          {task.due && task.column !== 'done' && (
                            <Text fontSize="xs" color={overdue ? 'danger-text' : 'text-muted'} dangerouslySetClassName={styles.metaItem}>
                              <CalendarDays aria-hidden size={12} />
                              <span className="visually-hidden">Due </span>
                              <time dateTime={task.due}>{shortDate(task.due)}</time>
                              {overdue && ' · Overdue'}
                            </Text>
                          )}
                          <Text fontSize="xs" color="text-muted" dangerouslySetClassName={styles.metaItem}>
                            <MessageSquare aria-hidden size={12} />
                            {task.comments}
                            <span className="visually-hidden">{task.comments === 1 ? ' comment' : ' comments'}</span>
                          </Text>
                          <span className={styles.assignees}>
                            {task.assignees.length === 0 ? (
                              <Text fontSize="xs" color="text-muted">
                                Unassigned
                              </Text>
                            ) : (
                              task.assignees.map((name) => (
                                <span key={name} className={styles.avatar} title={name}>
                                  <span aria-hidden>{initials(name)}</span>
                                  <span className="visually-hidden">Assigned to {name}</span>
                                </span>
                              ))
                            )}
                          </span>
                        </div>
                      </article>
                    </li>
                  )
                })}
              </ul>
              {columnTasks.length === 0 && (
                <BodySmall color="text-muted" marginY="none" marginX="sm">
                  No cards
                </BodySmall>
              )}
            </section>
          )
        })}
      </section>
    </Stack>
  )
}
```

## How it works

- **Moving is a menu action.** “Move to” lists the other columns. Moving re-renders the card in its new column, so focus follows it to the card’s menu button there, and a toast confirms where it went.
- **Limits are stated, not just tinted.** A column over its limit shows its count as “4 / 3”, a warning icon and “Over the work-in-progress limit”, and the column border picks up the warning color. Overdue dates turn red and also say “Overdue”.
- **Cards make sense when read aloud.** Each card is an `article` labelled by its title. Icons are hidden; visually hidden text supplies “Due”, “comments” and “Assigned to”.
- **The board scrolls inside itself.** Columns are sized so three fit and the fourth peeks in at the edge, which says there’s more. The board is a focusable, labelled region with a visible scrollbar and scroll snapping, so it never widens the page. Each card’s menu is a compact, borderless icon button that leaves the title its room.

## App-owned CSS

The scrolling board, columns, cards and stacked avatars.

`examples/recipes/kanban-board.module.css`:

```css
.kanban {
  container-type: inline-size;
}

/*
 * Columns are sized so three fit and the fourth visibly peeks in at the edge,
 * which says "scroll for more" without a fade. On a phone they keep a readable
 * minimum and the next column peeks the same way.
 */
.board {
  /* Positioned, so visually hidden text scrolls with the content instead of widening the page. */
  position: relative;
  display: grid;
  grid-auto-columns: minmax(11rem, calc((100% - 3 * var(--ds-space-md)) / 3.35));
  grid-auto-flow: column;
  gap: var(--ds-space-md);
  padding-bottom: var(--ds-space-md);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-color: var(--ds-color-border-strong) transparent;
  scrollbar-width: thin;

  &:focus-visible {
    outline: var(--ds-border-width-md) solid var(--ds-color-focus-ring);
    outline-offset: var(--ds-border-width-md);
  }
}

.column {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-md);
  padding: var(--ds-space-md);
  border: var(--ds-border-width-sm) solid transparent;
  border-radius: var(--ds-border-radius-xl);
  background-color: var(--ds-color-bg-subtle);
  scroll-snap-align: start;

  &[data-over-limit] {
    border-color: color-mix(in srgb, var(--ds-color-warning) 45%, transparent);
  }
}

.count {
  font-variant-numeric: tabular-nums;
}

.warning,
.metaItem {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-sm);
}

.warning {
  padding-inline: var(--ds-space-sm);
}

.cards {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-md);
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-md);
  padding: calc(var(--ds-space-md) + var(--ds-space-sm));
  border: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);
  border-radius: var(--ds-border-radius-md);
  background-color: var(--ds-color-bg);
  box-shadow: var(--ds-shadow-sm);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ds-space-md);
}

.assignees {
  display: flex;
  margin-left: auto;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: calc(var(--ds-space-xl) - var(--ds-space-sm));
  height: calc(var(--ds-space-xl) - var(--ds-space-sm));
  border: var(--ds-border-width-md) solid var(--ds-color-bg);
  border-radius: var(--ds-border-radius-circle);
  background-color: var(--ds-color-accent-subtle);
  color: var(--ds-color-accent-text);
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-semibold);

  & + & {
    margin-left: calc(var(--ds-space-md) * -1);
  }
}

/* A compact, borderless icon button so the menu doesn't crowd the title. */
button.iconButton {
  width: calc(var(--ds-space-lg) + var(--ds-space-md));
  min-height: calc(var(--ds-space-lg) + var(--ds-space-md));
  margin: calc(var(--ds-space-xs) * -1) calc(var(--ds-space-sm) * -1) 0 0;
  padding: 0;
  border-color: transparent;
  color: var(--ds-color-text-muted);
}

/* On a phone one column reads comfortably and the next peeks in. */
@container (max-width: 30rem) {
  .board {
    grid-auto-columns: 82%;
  }
}
```
