treeFilter
Narrows a file tree as the reader types into its filter field.
import { treeFilter } from "@sdxc/ui/app";View code
// 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
treeFilter(options: TreeFilter.Options): MixinDescriptor<HTMLInputElement>Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
options | TreeFilter.Options | Yes | The tree to narrow. |
Examples
<input type="search" name="filter" mix={[treeFilter({ tree: "files" })]} />Used with it
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.
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.
applyTreeFilter(tree: HTMLElement, query: string): number| Parameter | Type | Required | Description |
|---|---|---|---|
tree | HTMLElement | Yes | The tree's root element. |
query | string | Yes | What the reader typed; blank restores the whole tree. |
Interface
TreeFilter.Options
Options for treeFilter.
| Member | Type | Required | Description |
|---|---|---|---|
tree | string | Yes | The id of the tree the field narrows. |