Org Chart
Collapsible React org chart with CSS connector lines, initials avatars, team colour stripes, report counts on each manager and arrow key navigation.
Installation
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
import { OrgChart } from "@/components/ui/org-chart"
export function Example() {
return (
<OrgChart />
)
}
API reference
| Prop | Type | Default |
|---|---|---|
| dataThe root person. Defaults to Northwind's leadership, four levels deep with the lower branches folded. | OrgNode | SAMPLE |
| defaultExpandDepthNodes at or above this depth start expanded. The root is depth 0. | number | 0 |
| 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 | - |
| className | string | - |
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
| Key | Action |
|---|---|
| ArrowRightorArrowLeft | 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. |
| HomeorEnd | Moves to the first or last sibling. |
| EnterorSpace | 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-expandedon managers andaria-current="true"on the selected card. - The count pill is
aria-hiddenand out of the tab order; the avatar and team stripe arearia-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
Built from
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.