Solid API
createFileTree, the FileTree component, and the reactive primitives over the model.
Everything lives at the package root, solid-trees. The Solid layer is a thin
integration over one imperative model, FileTreeModel.
Model-first story
Start with createFileTree(options). Do not build a large controlled component.
The primitive creates one stable model for the owner’s lifetime. Later option
changes do not reconfigure the model. Update the model through model methods
instead.
import { createFileTree, FileTree } from 'solid-trees';
export function ProjectTree(props: { paths: readonly string[] }) {
const tree = createFileTree({ paths: props.paths, search: true });
return <FileTree model={tree} style={{ height: '320px' }} />;
} For the shared option meanings behind that call, read Shared concepts.
createFileTree(...)
createFileTree(...):
- accepts the shared tree-options surface
- creates the model one time
- cleans up the model when the current reactive owner disposes (called outside
an owner, call
cleanUp()yourself) - returns the
FileTreeModel
Use model methods when the tree changes after mount. The methods include
resetPaths(...), setComposition(...), setGitStatus(...), setIcons(...),
setLabels(...), and the search or mutation methods.
<FileTree />
The Solid component renders the model into the light DOM.
Primary props:
model- normal host HTML attributes such as
classandstyle
Composition props:
headerrenderContextMenu
Behavior notes:
- it renders a virtualized list, so give it a bounded height
- swapping the
modelprop remounts the view - the root DOM id comes from the model’s
idoption (<id>__tree), not anidprop headerandrenderContextMenuadd Solid rendering onto the model composition surface
Reading tree state from Solid
Model getters track inside Solid scopes and always return current values imperatively. Read them directly in JSX, or derive values through the primitives below. Solid code writes back through model methods.
Common read patterns include:
- selected paths for sibling panels or action bars
- search state for search inputs and result counts
- custom derived values such as “is this path focused?”
Primitives
createFileTreeSelector(model, selector, isEqual?)
- generic bridge from the model into a Solid memo
- returns an accessor for a value selected from the current model
- accepts an optional equality function when the selected value needs custom
comparison;
areArraysEqualcovers path lists
createFileTreeSelection(model)
- convenience accessor for
readonly string[]selected paths
createFileTreeSearch(model)
- returns the current search snapshot as the
stateaccessor, plus the model-backed actions - snapshot fields:
isOpen,matchingPaths,value - actions:
open(initialValue?),close(),setValue(value),focusNextMatch(),focusPreviousMatch()
const tree = createFileTree({ paths, search: true });
const selectedPaths = createFileTreeSelection(tree);
const search = createFileTreeSearch(tree);
const focusedPath = createFileTreeSelector(tree, (model) =>
model.getFocusedPath()
); Writing to the model from Solid
Solid writes through the imperative model methods.
Typical write paths are:
- focus and selection methods on the model or item handles. This includes
scrollToPath(...), which reveals a path without moving DOM focus and makes optional model focus changes. - visible-tree traversal through
focusFirstItem(),focusLastItem(),focusNextItem(),focusPreviousItem(), andfocusParentItem(). - visible row inspection through
getFocusedIndex(),getVisibleCount(), andgetVisibleRows(start, end)when surrounding UI needs custom navigation. - search methods such as
setSearch(...)andopenSearch(...) - mutation methods such as
add(...),remove(...),move(...),batch(...), andresetPaths(...) - runtime reconfiguration methods such as
setComposition(...),setGitStatus(...),setIcons(...), andsetLabels(...)
The full list is in Model API.
Composition surface
<FileTree> adds two composition props on top of the model:
headerfor Solid-rendered header content, above the search input and rowsrenderContextMenu(item, context)for Solid-rendered context menus; providing it enables the menu
Use composition.contextMenu on the model for the behavior flags (enabled,
triggerMode, buttonVisibility) and the onOpen / onClose callbacks. The
shared meaning of the composition options is in
Shared concepts.
Mutation and subscriptions from Solid
Use primitives and tracked getters when Solid UI needs reactive reads. Use
model.onMutation(...) when you need semantic side effects. Examples are
persistence, logging, or analytics around add, remove, move, reset, or batch
operations.
Appearance boundary
Style the host with normal host props such as class and style. For deeper
lookup, read Styling and theming and
Icons.