File Tree

Last updated: October 15, 2026

An animated, fully keyboard-navigable file tree with expand/collapse height animation and typeahead.

Installation

npx smoothui-cli add file-tree

Features

  • Recursive items data structure with files and folders
  • Controlled and uncontrolled expanded state and selection
  • Height-animated expand/collapse with a rotating chevron
  • Optional vertical guide lines connecting nested levels (showLines)
  • Full keyboard navigation with roving tabindex and typeahead
  • Custom per-item icons and badges
  • Respects prefers-reduced-motion

Accessibility

ARIA Attributes

AttributeElementPurpose
role="tree"Root containerIdentifies the widget as a tree
role="treeitem"Each rowIdentifies a selectable/expandable node
role="group"Children wrapperGroups a folder's nested items
aria-expandedFolder rows onlyWhether the folder's children are visible
aria-levelEach rowDepth of the node within the tree
aria-selectedEach rowWhether the node is the current selection

Keyboard

KeyAction
Arrow Down / Arrow UpMove focus to the next/previous visible node
Arrow RightExpand a collapsed folder, or move into its first child
Arrow LeftCollapse an expanded folder, or move to its parent
Home / EndJump to the first/last visible node
Enter / SpaceSelect the focused node
Letter keyJump to the next visible node starting with that letter

Screen Reader

  • Only one node is in the tab sequence at a time (roving tabindex); arrow keys move a virtual focus that screen readers announce via aria-level, aria-expanded and aria-selected.
  • Nested children are wrapped in role="group" so their depth and relationship to the parent folder are announced correctly.

Reduced Motion

When prefers-reduced-motion is enabled, folders expand and collapse instantly with no height transition, and the chevron snaps to its rotated state instead of animating.

Props

Created by

Improved by

Eduardo Calvo's avatar

Powered by

motion.dev
lucide.dev