Skip to content

FileTree reference ​

FileTree, useFileTree and the types below come from @adecore/ui. FileTreeModel, FileTreeVisibleRow, FileTreeDragAndDropConfig, FileTreeDropContext and FileTreeDropResult are the engine's own types under these names; FileTreeModel is a type, not a class you construct. FILE_TREE_ICONS is the icon set the hook passes by default.

useFileTree ​

useFileTree(options) returns { model }. FileTreeOptions is every option of the engine except density and itemHeight: paths (or its prepared form), initialExpansion, initialExpandedPaths, initialSelectedPaths, flattenEmptyDirectories, sort, gitStatus, icons, search, stickyFolders, composition, renaming, dragAndDrop, onSelectionChange, unsafeCSS and the rest.

The options create the model once; they are not controlled. The hook keeps only onSelectionChange current, so read changing values in other callbacks through a ref. The defaults are on the overview.

FileTree.Root ​

PropTypeDefault
modelFileTreeModelRequired.
labelstring"Files"The tree's accessible name (tree.label).
resetKeystringPuts the sideways shift back at zero when it changes.
selectionFollowsFocusbooleantrueSelects the row the arrow keys land on.
onActivate(path: string) => voidA plain click or Enter on a file.
onFocusMove(path: string) => voidFocus moved to another row, while selection follows focus.
onLoadChildren(path: string) => voidA directory opened. Not awaited.
onExpandedPathsChange(paths: readonly string[]) => voidEvery open directory, including remembered ones under a closed directory.
onRowContextMenu(path, targets, event: MouseEvent) => voidYour code opens the menu.
onRowDragStart(path, targets, event: DragEvent) => voidAfter the engine wrote its drag data.
renderControl(row: FileTreeVisibleRow) => ReactNodeDrawn before the icon.
renderDecoration(row: FileTreeVisibleRow) => ReactNodeDrawn after the name.
rowIcon(row: FileTreeVisibleRow) => LucideIcon | undefinedA 14 pixel icon in place of the row's file icon or chevron; undefined keeps it.
fitContentbooleanfalseAs tall as its rows, up to the height its container leaves it.
highlightstring''Marks where this occurs in every name, ignoring case, in --match.
emptyLabel(row: FileTreeVisibleRow) => string | undefinedA muted line under an open directory with nothing in it; undefined draws none. See empty directories.
decorationOrder'before-status' | 'after-status''before-status'Whether the decoration comes before or after the git status column.
treePropsengine React props without modelFor the engine's own tree element, such as its header or context menu rendering.
renderRenderPropAnother element to be the frame.

Every other prop goes to the frame, a <div>. There is no onLoadError and no controlled expansion. FileTreeRootProps is the type.

Parts ​

FileTree.Checkbox, FileTree.Control and FileTree.Decoration are the Tree parts of the same name, drawn in the row slots. See Interaction and row controls.

Helpers ​

HelperReturns or does
FileTree.directoryHandle(model, path)The directory's handle, or null for a file.
FileTree.pathOfRow(row)The path of the last directory of a flattened row.
FileTree.visibleRows(model)The visible rows, with that path.
FileTree.resetExpandedPaths(model, paths, expanded)Resets the paths and expands expanded in a second pass.
FileTree.applyExpansion(model, collapsed, keyOf?)Folds and opens directories to match collapsed.
FileTree.collapsedPathsOf(rows, keyOf?)The keys of the closed directories.
FileTree.mergeCollapsedPaths(current, rows, keyOf?)current with the visible folds applied; the same array when nothing changed.
FileTree.expansionChanges(rows, collapsed, keyOf?){ collapse, expand }, the paths that differ from collapsed.
FileTree.dirPathOf(path)The path without its trailing slash.
FileTree.ancestorDirsOf(path)The directories above a path, outermost first.
FileTree.mergeExpanded(remembered, reported, known)reported plus the remembered paths the model does not know yet.
FileTree.withoutClosedBranches(open, known)open without the paths under a known closed directory.
FileTree.newlyExpanded(before, after)The paths in after that were not in before.
FileTree.compareRows(left, right)Directories first, then names in numeric order.
FileTree.selectOnly(model, path)Selects one path; null clears the selection.
FileTree.focusRow(model, path)Focuses a drawn row; false when it is not drawn.
FileTree.rebuildPaths(model, paths, fold, applying)Resets the paths, moving selection and focus to the nearest row when theirs went. fold runs in between with applying.current set, so you can ignore the fold reports it causes.
FileTree.followFocus(model, onMoved?)Selects the focused row after the engine moved it; returns a cancel function.
FileTree.movesFocus(event)Whether a key is an arrow, Home or End without a modifier.
FileTree.extendsSelection(event)Whether Shift, Ctrl or Cmd is down.
FileTree.rowPathOf(event)The row path of an event, through the shadow root, or null.
FileTree.menuTargetsOf(row, selected)The selection when it holds the row and more, otherwise the row alone.

FoldKeyOf is (rowPath: string) => string | null. SortRow is { isDirectory, segments }.

Moving from a tree of your own ​

The wrapper replaces row styling, icon mapping, row and chevron sizes, truncation and the sideways shift. Keep your sort overrides, file and Git commands, listing and search caches, path resolution, placeholders and fold keys. Replace a drawn checkbox with FileTree.Checkbox, and move status into renderDecoration.

Engine updates ​

The wrapper depends on internals of @pierre/trees 1.0.0-beta.6, so it pins that version.

Licenses and third-party notices are listed in each package.