Skip to content
IndexRequest a UIAboutContact

File Tree Expand and Collapse

A nested folder tree with chevrons that rotate, full arrow-key navigation and a selected-file readout.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Clean UI mockup of a file explorer sidebar tree in a light theme, folder rows with small chevrons, src open showing components and utils folders and a few files with simple icons, one file selected with a soft dark highlight and a left accent bar, indentation levels clearly visible, thin vertical guide lines, flat modern style. Negative: heavy shadows, clutter, text errors, device frames. Reduced motion: static design.

About this pattern

Definition

A tree view shows nested items such as folders and files. It must work with the keyboard: Down and Up move between visible items, Right opens a folder or moves into it, Left closes it or goes to the parent, Home and End jump to the ends. A chevron that rotates shows the open state.

Purpose & UX principles

  • Use role tree on the list, treeitem on items and group on nested lists; set aria-expanded on folders.
  • Use one tab stop (roving tabindex) so Tab leaves the tree after one stop.
  • Indent children by a fixed step and show the selected item clearly.
  • Typing a letter can jump to the next item that starts with it.

Interaction states

  • Click or use the arrow keys; Enter selects a file.

Motion specification

  • Chevrons rotate in 150ms.
  • Reduced motion: no rotation animation.

Responsive behaviour

  • Hidden children must not be focusable.
  • Do not rely on colour alone for selection; add a left bar or background.

Code

HTML
<div class="bx"><ul class="tr" id="tr" role="tree" aria-label="Project files"></ul><p class="out" id="out" role="status"></p></div>

Related patterns

Accordion

↗
AccordionCards & Containers

Breadcrumb

↗
BreadcrumbNavigation

Sidebar

↗
SidebarNavigation