# Org Chart

> Collapsible React org chart with CSS connector lines, initials avatars, team colour stripes, report counts on each manager and arrow key navigation.

- Kind: Component (Dashboard)
- Docs: https://ui.minidev.pro/docs/org-chart
- Source (registry JSON with the full file): https://ui.minidev.pro/r/org-chart.json
- License: MIT. One file, yours to edit after install.

## When to use

Cards carry an initials avatar, name, role and a team coloured stripe; a pill under each manager shows how many people report up and folds the branch on a spring. Connectors are plain CSS borders and the tree scrolls sideways when wider than its container. Keyboard: one tab stop; ArrowLeft/Right walk siblings, ArrowDown opens or enters reports, ArrowUp goes to the manager, Home/End jump, Enter/Space selects and toggles. Use it for people directories and admin consoles; for a file-style hierarchy use TreeView, for a sidebar menu use NestedNav.

## Installation

### shadcn CLI (copies the source into your project)

```bash
npx shadcn@latest add @minidev/org-chart
```

Writes `components/ui/org-chart.tsx` and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/org-chart.json`.

### npm package

```bash
npm i minidev-ui-kit lucide-react motion
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { OrgChart } from "@/components/ui/org-chart"
```

From the npm package:

```tsx
import { OrgChart } from "minidev-ui-kit/ui/org-chart"
```

## Usage

```tsx
import { OrgChart } from "@/components/ui/org-chart"

export function Example() {
  return (
    <OrgChart />
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `data` | `OrgNode` | `SAMPLE` | no | The root person. Defaults to Northwind's leadership, four levels deep with the lower branches folded. |
| `defaultExpandDepth` | `number` | `0` | no | Nodes at or above this depth start expanded. The root is depth 0. |
| `defaultExpanded` | `string[]` | `data === SAMPLE ? ["theo"] : []` | no | Extra node ids that start expanded. |
| `selectedId` | `string` | - | no | Controlled selected node id. |
| `defaultSelectedId` | `string` | - | no | Initially selected node id when uncontrolled. |
| `onSelect` | `(node: OrgNode) => void` | - | no | Called when a node is clicked or activated. |
| `teamTones` | `Partial<Record<string, OrgTone>>` | - | no | Pin team names to colours. Unlisted teams are coloured in order. |
| `aria-label` | `string` | - | no | Accessible name for the tree. |
| `className` | `string` | - | no |  |

## Examples

### Custom data, fully open

data is a nested tree of people; defaultExpandDepth 2 opens every branch of this three level team.

```tsx
const engineering: OrgNode = {
  id: "theo",
  name: "Theo Okafor",
  role: "CTO",
  team: "Engineering",
  children: [
    {
      id: "priya",
      name: "Priya Raman",
      role: "VP Engineering",
      team: "Engineering",
      children: [
        { id: "sam", name: "Sam Lowe", role: "Staff Engineer", team: "Engineering" },
        { id: "ines", name: "Inès Moreau", role: "Engineer, Payments", team: "Engineering" },
      ],
    },
    {
      id: "lena",
      name: "Lena Fischer",
      role: "Head of Design",
      team: "Design",
      children: [{ id: "kai", name: "Kai Nakamura", role: "Product Designer", team: "Design" }],
    },
    { id: "omar", name: "Omar Siddiqui", role: "Security Lead", team: "Security" },
  ],
}

<OrgChart data={engineering} defaultExpandDepth={2} />
```

### Controlled selection

selectedId and onSelect make the chart a picker; the clicked node drives whatever detail view sits next to it.

```tsx
function SelectDemo() {
  const [person, setPerson] = React.useState<OrgNode>(engineering)
  return (
    <div className="flex w-full max-w-3xl flex-col gap-3">
      <OrgChart data={engineering} defaultExpandDepth={1} selectedId={person.id} onSelect={setPerson} aria-label="Engineering org chart" />
      <div className="flex items-center justify-between gap-3 rounded-lg border border-border bg-surface px-3 py-2 text-sm">
        <span>
          <span className="font-medium text-fg">{person.name}</span>
          <span className="text-fg-muted"> · {person.role}</span>
        </span>
        <span className="text-xs text-fg-subtle">
          {person.children?.length ? `${person.children.length} direct ${person.children.length === 1 ? "report" : "reports"}` : "No direct reports"}
        </span>
      </div>
    </div>
  )
}
```

### Pinned team colours

Teams are coloured in order of appearance by default; teamTones pins names to tones so Finance stays warning coloured on every page.

```tsx
<OrgChart
  defaultExpandDepth={1}
  teamTones={{ Leadership: "neutral", Engineering: "accent", Finance: "warning", Operations: "info", Design: "success" }}
/>
```

## Keyboard interactions

| Key | Action |
| --- | --- |
| `ArrowRight` or `ArrowLeft` | Moves to the next or previous sibling. |
| `ArrowDown` | Opens a closed manager, or moves to the first report of an open one. |
| `ArrowUp` | Moves to the manager. |
| `Home` or `End` | Moves to the first or last sibling. |
| `Enter` or `Space` | Selects the person and folds or unfolds their reports. |

## Accessibility

- One tab stop: the focused card, else the selected one, else the root. Folding a branch that holds focus moves focus to its manager.
- Each card is a button named "Theo Okafor, CTO, Engineering, 3 reports" (the count is everyone below them, not only direct reports), with `aria-expanded` on managers and `aria-current="true"` on the selected card.
- The count pill is `aria-hidden` and out of the tab order; the avatar and team stripe are `aria-hidden`.
- With reduced motion branches open and close at once and cards don't animate to their new positions.

## FAQ

### Why doesn't clicking a manager fold the branch?

A click selects the card and calls `onSelect`. Folding is on the count pill under the card, or Enter and Space on the keyboard, so opening a profile and browsing the tree don't get in each other's way.

### How do I control which branches start open?

`defaultExpandDepth` opens every manager at or above that depth (the root is 0), and `defaultExpanded` adds specific ids. After that the chart keeps the open state itself; there is no controlled prop.

### How do I fix a team's colour?

Pass `teamTones`, for example `teamTones={{ Engineering: "info", Finance: "success" }}`. Teams you don't list get the next tone in order of first appearance.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `lucide-react`, `motion`

## Related

- [Tree View](https://ui.minidev.pro/docs/tree-view/md): Nested tree view with expandable nodes, rotating chevrons, depth indentation and ARIA tree roles. Suited to file explorers and nested category lists in React.
- [Nested Nav](https://ui.minidev.pro/docs/nested-nav/md): A collapsible tree navigation built from nested node data, indented by depth with rotating chevrons on items that have children. Fits React docs sidebars.
- [Account Setup Progress](https://ui.minidev.pro/docs/account-setup-progress/md): React onboarding card that shows account setup as completed steps out of a total, with a labelled progress bar and a hint for the next step to finish.
- [Activity Feed](https://ui.minidev.pro/docs/activity-feed/md): React activity feed that lists who did what and when, with initials avatars, muted action text and tabular timestamps in a single bordered card.
- [Admin Stat Strip](https://ui.minidev.pro/docs/admin-stat-strip/md): Responsive Tailwind row of admin KPI tiles, each with a label, a large tabular value and an optional up or down delta. Collapses from four columns to one.
- [Calendar Agenda](https://ui.minidev.pro/docs/calendar-agenda/md): React agenda list of the day's events with a fixed time column, title and optional meta line such as location or attendees, divided inside one card.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
