Tree

Usage, with a search field

An input[type="search"] inside .tree filters files as you type. Matching files stay visible and their folders open. The last p shows when nothing matches.

Folders can nest, links can sit outside any folder, and icons are optional

aria-current marks the open file, and open on its details shows it

A script filters the files with filter()

An empty query shows every file and restores each folder's open state.

API

Lives in js/tree.js. A tree without a search field needs no JS. It fires no events of its own; details fires the browser's toggle.

Function Arguments Description
tsunami.tree.filter(tree, query) tree: element .tree, query: string Shows only files whose name contains query (case-insensitive). Hides folders with no match and opens folders with one. An empty query shows every file and restores the folders.
input[type="search"] in .tree Calls filter() as you type
Tab / Enter / Space keyboard Native browser behaviour: move between folders and files, open and close folders, follow links

Attributes

Attribute / element Values Description
.tree nav Add an aria-label (ul.tree also works)
ul > li child One item each. A ul nested in an li is indented on a guide line.
details > summary in li Folder. The chevron turns when open. Followed by a ul of files.
open on details Folder is open (native)
a / span in li File (link) or a non-link item. The label in its span truncates with … when long.
.icon in summary / a Optional, such as icon-folder, icon-file
aria-current page On a link: the open file
input[type="search"] direct child of .tree Search field, filters as you type
p direct child of .tree Message when no file matches. Start it hidden; JS shows and hides it.
hidden on li Set by JS on files and folders that do not match