Skip to content
Hazine

File Tree

Collapsible folder and file tree with indent guides, file type icons and one open file, plus an optional path line. Use it for code browsers and docs sidebars.

How it differs. Baseline single-select tree: indent guides that darken beside the open file, a dot on a closed folder that holds it, and the full APG keyboard map with typeahead and asterisk.

Install

pnpm dlx shadcn@latest add @hazine/tree-view-file-explorer

Adds 1 file, 1 Hazine item (@hazine/use-controllable-state), and 1 package (lucide-react).

First time? Add the registry to components.json
{
  "registries": {
    "@hazine": "https://api.hazine.dev/r/{name}.json"
  }
}

Needed once per project. Items resolve each other through the @hazine namespace.

Props15

nodes
FileTreeNode[] = DEFAULT_NODES
value
string | null
Id of the open file. Pass `null` for none.
defaultValue
string | null = null
onValueChange
(value: string | null) => void
expanded
string[]
defaultExpanded
string[] = DEFAULT_EXPANDED
onExpandedChange
(expanded: string[]) => void
label
string = "Files"
Accessible name of the tree.
loading
boolean = false
Shows skeleton rows and marks the tree busy.
showPath
boolean = false
Adds a line under the tree with the path of the open file and the file count.
emptyLabel
string = "No files yet. Files added to this project appear here."
emptyAction
React.ReactNode
One action offered under the empty message.
noSelectionLabel
string = "No file open"
Path line text while no file is open.
containsSelectionLabel
string = "Contains the open file"
Read out on a closed folder that holds the open file.
formatCount
(count: number) => string = defaultFormatCount

Also accepts every prop of Omit< React.ComponentProps<"div">, "children" | "defaultValue" | "onChange" >.

Accessibility

Keyboard
Keyboard support for File Tree
KeyEffect
TabEnters the tree on the last focused row, the open file or the first row, and leaves it again
Arrow Down, Arrow UpMoves focus to the next or previous visible row
Arrow RightOpens a closed folder, or moves into the first child of an open one. Arrow Left does this in right to left layouts
Arrow LeftCloses an open folder, or moves to the parent folder. Arrow Right does this in right to left layouts. A disabled folder stays as it is
Home, EndMoves focus to the first or last visible row
Enter or SpaceOpens the focused file, or opens and closes the focused folder. Does nothing on a disabled row
AsteriskOpens every folder at the same level as the focused row, except disabled ones
Letters and digitsMoves focus to the next visible row whose name starts with the typed characters. Repeating one character steps through its matches
Screen reader

A labelled tree of treeitem rows with aria-level, aria-setsize and aria-posinset, aria-expanded on folders and aria-selected on files. Rows are divs with the treeitem role because no native element carries it, and each group is a sibling of its row so the name and focus outline cover one row. Disabled rows carry aria-disabled and stay reachable with the arrow keys.

Reduced motion
The chevron turns without a transition and skeleton rows do not pulse. Colour transitions only.
Checked
Not checked yet. Automated results appear here once CI has run.

Dependencies2

  • @hazine/use-controllable-state
  • lucide-react

Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.

Tokens shipped0

None. The item is styled by the tokens your theme already has.

More in Navigation