SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

treeFilter

Narrows a file tree as the reader types into its filter field.

tsx
import { treeFilter } from "@sdxc/ui/app";
View code
tsx
// Tree.Filter's field carries treeFilter({ tree }), which narrows the tree on every keystroke.
<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>

Usage

Filters the tree named by options.tree on every keystroke in the field it is applied to, and moves focus from the field into the first visible row on ArrowDown, so a reader types, then walks the results.

Signature

typescript
treeFilter(options: TreeFilter.Options): MixinDescriptor<HTMLInputElement>

Parameters

ParameterTypeRequiredDescription
optionsTreeFilter.OptionsYesThe tree to narrow.

Examples

tsx
<input type="search" name="filter" mix={[treeFilter({ tree: "files" })]} />

The events, constants and types its module publishes, each imported from @sdxc/ui/app too.

Constant

TREE_FILTER_TEXT_ATTRIBUTE

Attribute every file row carries, holding the path the filter matches.

typescript
const TREE_FILTER_TEXT_ATTRIBUTE = "data-filter-text"
Function

applyTreeFilter

Applies query to every row in tree. Folders are visited deepest first, so a folder reads its subfolders' final state when it decides whether it still holds a match; the tree's no-matches line shows only while a query leaves no file.

typescript
applyTreeFilter(tree: HTMLElement, query: string): number
ParameterTypeRequiredDescription
treeHTMLElementYesThe tree's root element.
querystringYesWhat the reader typed; blank restores the whole tree.
Interface

TreeFilter.Options

Options for treeFilter.

MemberTypeRequiredDescription
treestringYesThe id of the tree the field narrows.
@sdxc/ui

Can’t find it? Contact us