Skip to content

Tree<T>

Unofficial

Hierarchical tree view UI component used for file explorers, search results, and similar views.

Import:

import type { Tree } from '@obsidian-typings/obsidian-public-latest';

Signature:

export interface Tree<T extends TreeItem>

Properties

Property Type Description
activeDom null | T Currently active item in tree view.
app App Reference to the obsidian#App.
containerEl HTMLElement Container element of the tree view.
focusedItem null | T Currently focused item in tree view.
id string ID of the view the tree is associated with.
infinityScroll InfinityScroll Facilitates rendering of tree view.
isAllCollapsed boolean Whether all items in the tree are collapsed.
prefersCollapsed boolean Whether tree items should default to collapsed state.
scope Scope Key scope for tree view.
selectedDoms Set<T> Currently selected items in tree view.
view View The view the tree is associated with.

Methods

Method Returns Description
changeFocusedItem(direction) void Change the focused item to the next item in specified direction.
clearSelectedDoms() void Unselect all selected items in the tree view.
deselectItem(node) void Mark tree item as deselected.
getFoldKey() string Get the local storage key for the saved tree view folds.
getNodeId(node) string | undefined Gets the ID of a tree item given its Node.
handleCollapseAll() void Handle collapsing of all nodes.
handleDeleteSelectedItems(event) Promise<void> Handle deletion of selected nodes.
handleItemSelection(event, node) void Handle selection of tree item via keyboard event.
handleRenameFocusedItem(event) void Handle renaming of focused item.
initializeKeyboardNav() void Registers all keyboard actions to the tree view keyscope.
isItem(node) boolean Check whether item is a valid tree item.
loadFolds() void Load the saved fold states of the tree view from local storage.
onKeyArrowDown(event) void Handle keyboard event for moving/selecting tree item below.
onKeyArrowLeft(event) void Handle keyboard event for moving through the hierarchy of tree items (and/or folding/unfolding).
onKeyArrowRight(event) void Handle keyboard event for moving through the hierarchy of tree items (and/or folding/unfolding).
onKeyArrowUp(event) void Handle keyboard event for moving/selecting tree item above.
onKeyOpen(event) void Handle keyboard event for opening tree item.
onResize() void Update scroll representation on resize.
requestSaveFolds() void Request saving of the current fold states.
saveFolds() void Save the current fold states of the tree view to local storage.
selectItem(node) void Mark tree item as selected.
setCollapseAll(collapse) void Set all items in the tree view to be collapsed or expanded.
setFocusedItem(node, scrollIntoView?) void Set the focused item in the tree view.
toggleCollapseAll() void (Un)Collapse all items in the tree view.

Links to this page: