Skip to content

File Trees for React and Tailwind

Anything that holds files or nested content needs a tree people can open and close without losing their place. Good file trees show depth clearly, remember what is expanded, support the arrow keys and stay readable when names run long. Try each one live with a deep folder, then install it into your project as code you own and wire it to your own data.

About file trees

File trees show nested folders and files that open and close, like the explorer in a code editor. The same pattern serves documentation navigation, nested categories, organisation charts and any hierarchy people browse, with icons by file type, indentation guides and selection.

Large trees need care: render only visible rows, load children when a folder opens, and remember which folders were expanded. Arrow keys should move through the tree and open and close folders, following the tree view pattern screen readers know.

Frequently asked questions

Render nested lists from your data, track which nodes are expanded and indent each level. Libraries such as react-arborist or headless tree hooks add keyboard support, drag and drop and virtualisation.

Use the tree and treeitem roles with aria-expanded and aria-level. Up and Down move between visible items, Right opens a folder and Left closes it or moves to the parent.

Flatten the visible part of the tree into a list and virtualise it, so only rows on screen are rendered. Load each folder's children when it's first opened.

Yes. Show where an item will land, between rows or inside a folder, prevent dropping a folder into itself, and offer a keyboard way to move items too.

Map each extension to an icon, with a fallback for unknown types, and show an open or closed folder icon depending on state.

Save the set of expanded node ids to local storage or the URL and restore it when the tree mounts.

Use a tree when people browse and compare items at several levels at once, like files. Use menus when they pick one action and move on.

Explore more