Skip to content

Org Chart

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

src/registry/ui/org-chart.tsx/r/org-chart.json

Installation

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

MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/org-chart.json

Usage

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

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

API reference

OrgChart props
PropTypeDefault
dataThe root person. Defaults to Northwind's leadership, four levels deep with the lower branches folded.OrgNodeSAMPLE
defaultExpandDepthNodes at or above this depth start expanded. The root is depth 0.number0
defaultExpandedExtra node ids that start expanded.string[]data === SAMPLE ? ["theo"] : []
selectedIdControlled selected node id.string-
defaultSelectedIdInitially selected node id when uncontrolled.string-
onSelectCalled when a node is clicked or activated.(node: OrgNode) => void-
teamTonesPin team names to colours. Unlisted teams are coloured in order.Partial<Record<string, OrgTone>>-
aria-labelAccessible name for the tree.string-
classNamestring-

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.

Keyboard interactions

Keyboard interactions
KeyAction
ArrowRightorArrowLeftMoves to the next or previous sibling.
ArrowDownOpens a closed manager, or moves to the first report of an open one.
ArrowUpMoves to the manager.
HomeorEndMoves to the first or last sibling.
EnterorSpaceSelects 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.

Frequently asked questions

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.

Dependencies

npm

lucide-reactmotion

Built from

No other MiniDev files

Examples

Custom data, fully open

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

Controlled selection

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

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.

All dashboard components

Learn more