SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

Tree

A hierarchical list of nodes built from nested <details> and <summary> elements.

packages
ui
tree.tsx
table.tsx
treeKeys.ts
package.json
index.ts
1 files selectedArrows move · type to jump · Enter selects
View code
tsx
let model = new SelectionModel({
	mode: "multiple",
	keys,
	selectedKeys: ["packages/ui/package.json"],
});
model.addEventListener("change", () => void handle.update());

<Tree aria-label="Repository files" aria-multiselectable="true" mix={[treeKeys(model)]}>
	<Tree.Item id="packages" open>
		<Tree.ItemContent data-tree-item="packages" aria-expanded="true">
			<Tree.ExpandButton />
			<FolderIcon aria-hidden="true" />
			packages
		</Tree.ItemContent>

		<Tree.Item id="packages-ui" open>
			<Tree.ItemContent data-tree-item="packages/ui" aria-expanded="true">
				<Tree.ExpandButton />
				<FolderIcon aria-hidden="true" />
				ui
			</Tree.ItemContent>

			<Tree.Item id="packages-ui-components">
				<Tree.ItemContent data-tree-item="packages/ui/components" aria-expanded="false">
					<Tree.ExpandButton />
					<FolderIcon aria-hidden="true" />
					components
				</Tree.ItemContent>

				<Tree.Item id="packages-ui-components-tree">
					<Tree.ItemContent data-tree-item="packages/ui/components/tree.tsx">
						<FileCodeIcon aria-hidden="true" />
						tree.tsx
					</Tree.ItemContent>
				</Tree.Item>
				<Tree.Item id="packages-ui-components-table">
					<Tree.ItemContent data-tree-item="packages/ui/components/table.tsx">
						<FileCodeIcon aria-hidden="true" />
						table.tsx
					</Tree.ItemContent>
				</Tree.Item>
			</Tree.Item>

			<Tree.Item id="packages-ui-mixins">
				<Tree.ItemContent data-tree-item="packages/ui/mixins" aria-expanded="false">
					<Tree.ExpandButton />
					<FolderIcon aria-hidden="true" />
					mixins
				</Tree.ItemContent>
				<Tree.Item id="packages-ui-mixins-tree-keys">
					<Tree.ItemContent data-tree-item="packages/ui/mixins/treeKeys.ts">
						<FileCodeIcon aria-hidden="true" />
						treeKeys.ts
					</Tree.ItemContent>
				</Tree.Item>
			</Tree.Item>

			<Tree.Item id="packages-ui-package-json">
				<Tree.ItemContent data-tree-item="packages/ui/package.json">
					<FileBracesIcon aria-hidden="true" />
					package.json
				</Tree.ItemContent>
			</Tree.Item>
		</Tree.Item>

		<Tree.Item id="packages-result">
			<Tree.ItemContent data-tree-item="packages/result" aria-expanded="false">
				<Tree.ExpandButton />
				<FolderIcon aria-hidden="true" />
				result
			</Tree.ItemContent>
			<Tree.Item id="packages-result-index">
				<Tree.ItemContent data-tree-item="packages/result/index.ts">
					<FileCodeIcon aria-hidden="true" />
					index.ts
				</Tree.ItemContent>
			</Tree.Item>
		</Tree.Item>
	</Tree.Item>
</Tree>

Demo apps

Whole pages built only from @sdxc/ui, each for an invented product with its own palette and type. They open in a new tab.

Every demo, landings and docs sites alike, is listed in the showcase.

Installation

An ordinary dependency: install it, import the theme once, and import the component where it is used.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Usage

typescript
import { Tree } from "@sdxc/ui/app";

Renders the bordered role="tree" panel; folders open and file links work with no script. Rows indent --ui-tree-indent per level, frame aims every Tree.Leaf at one frame, data-empty centers a fallback, Tree.NoMatches answers a filter that matches nothing, and Tree.Filter and Tree.Navigation add islands.

Composition

The parts the component publishes, each a static property of the host.

  • Tree
  • Tree.ItemContentRenders Tree.ItemContentProps.children inside a native <summary> — the enclosing Tree.Item's always-visible row — indented from its ambient depth, with aria-selected/aria-disabled styling.
  • Tree.ExpandButtonRenders the chevron a node's row shows for a subtree, rotated 90 degrees while the enclosing Tree.Item's <details> carries [open].
  • Tree.LeafRenders a file: a link row with the file's icon and name, indented from the depth of the folders around it, as a role="treeitem" so arrow keys reach it beside the folders.
  • Tree.FilterRenders a "Go to file" field over a tree: a GET form (?filter= by default), so without script the server renders the narrowed tree with treeFilterMatches.
  • Tree.NoMatchesRenders the line a tree shows while its filter matches no file, such as "No file matches", inside the tree or beside it with tree naming the tree's id.
  • Tree.NavigationAdds the keys as the TreeNavigation island running treeNavigation: ↑↓ and j/k between visible rows, → opens or enters a folder, ← closes it or goes up, Home/End and type-ahead.

Examples

Changed files, with a filter and the arrow keys

View code
tsx
<Tree.Filter tree="changed-files" label="Filter changed files" placeholder="Filter changed files…" action="/acme/delta/pull/412/files" />

<Tree id="changed-files" aria-label="Changed files" frame="diff">
	<Tree.Navigation labels={{ group: "Changed files" }} />
	<Tree.Item id="src" open>
		<Tree.ItemContent aria-expanded="true">
			<Tree.ExpandButton />
			<FolderIcon aria-hidden="true" />
			src
		</Tree.ItemContent>
		<Tree.Item id="src-lexer" open>
			<Tree.ItemContent aria-expanded="true">
				<Tree.ExpandButton />
				<FolderIcon aria-hidden="true" />
				lexer
			</Tree.ItemContent>
			<Tree.Leaf
				href="/acme/delta/pull/412/files#diff-identifier"
				name="identifier.ts"
				path="src/lexer/identifier.ts"
				current
				status="modified"
				statusLabel="Modified"
				additions={18}
				deletions={4}
			/>
			<Tree.Leaf href="…" name="unicode.ts" path="src/lexer/unicode.ts" status="added" statusLabel="Added" additions={96} />
			…
		</Tree.Item>
	</Tree.Item>
</Tree>

Empty

No files in this folder yet.
View code
tsx
<Tree aria-label="Files" data-empty>
	No files in this folder yet.
</Tree>

Props

Read from the component's own types, so every prop, every default and every allowed value is listed.

PropTypeDefaultRequiredDescription
childrenRemixNode—YesTree.Item, Tree.Leaf and Tree.LoadMoreItem nodes to render.
framestring—NoThe frame every file link swaps (data-rmx-target), such as "main", so picking a file redraws only the code while the tree, its open folders and scroll stay put.

Also accepts everything in TagProps<"div">.

Tree.ItemContent

Also accepts everything in TagProps<"summary">.

Tree.ExpandButton

Also accepts everything in TagProps<"span">.

Tree.Leaf

PropTypeDefaultRequiredDescription
hrefstring—Yes
namestring—YesThe file's name; picks its icon and is what type-ahead matches.
pathstring—NoThe file's full path, which Tree.Filter matches. @default name
childrenRemixNode—NoWhat the row shows in place of name, such as a name with a matched part marked.
currentboolean—NoMarks the file being read, with aria-current="page"; render its folders open.
framestring—NoThe frame this link swaps, over the tree's own frame.
status"added" | "modified" | "deleted" | "renamed"—No
statusLabelstring—NoWhat assistive technology reads for status, such as "Modified"; the letter is decoration.
additionsnumber—NoLines added, drawn end-aligned as +n.
deletionsnumber—NoLines removed, drawn end-aligned as −n.

Also accepts everything in Omit<TagProps<"a">, "children" | "role" | "href">.

Tree.Filter

PropTypeDefaultRequiredDescription
treestring—YesThe id of the Tree the field narrows as the reader types.
labelstring—YesThe field's accessible name, such as "Filter files".
placeholderstring—No
valuestring—NoThe query the page was rendered with, so the field shows what narrowed the tree.
namestring—NoSearch parameter the query submits under. @default "filter"
paramsRecord<string, string>—NoOther search parameters the submission keeps, as hidden fields.

Also accepts everything in Omit<TagProps<"form">, "children" | "method">.

Tree.NoMatches

PropTypeDefaultRequiredDescription
treestring—NoThe id of the tree it answers for, when it sits beside the tree rather than inside it, which keeps the tree's children to its items.

Also accepts everything in TagProps<"p">.

Tree.Navigation

PropTypeDefaultRequiredDescription
labelsTreeNavigationMixin.Labels—No

Types

NameValuesWhat it decides
LeafStatus"added" | "modified" | "deleted" | "renamed"How a file changed, drawn as a toned letter: A, M, D or R.
@sdxc/ui

Can’t find it? Contact us