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

PropertyTypeDescription
activeDomnull | TCurrently active item in tree view.
appAppReference to the obsidian#App.
containerElHTMLElementContainer element of the tree view.
focusedItemnull | TCurrently focused item in tree view.
idstringID of the view the tree is associated with.
infinityScrollInfinityScrollFacilitates rendering of tree view.
isAllCollapsedbooleanWhether all items in the tree are collapsed.
prefersCollapsedbooleanWhether tree items should default to collapsed state.
scopeScopeKey scope for tree view.
selectedDomsSet<T>Currently selected items in tree view.
viewViewThe view the tree is associated with.

Methods

MethodReturnsDescription
changeFocusedItem(direction)voidChange the focused item to the next item in specified direction.
clearSelectedDoms()voidUnselect all selected items in the tree view.
deselectItem(node)voidMark tree item as deselected.
getFoldKey()stringGet the local storage key for the saved tree view folds.
getNodeId(node)string | undefinedGets the ID of a tree item given its Node.
handleCollapseAll()voidHandle collapsing of all nodes.
handleDeleteSelectedItems(event)Promise<void>Handle deletion of selected nodes.
handleItemSelection(event, node)voidHandle selection of tree item via keyboard event.
handleRenameFocusedItem(event)voidHandle renaming of focused item.
initializeKeyboardNav()voidRegisters all keyboard actions to the tree view keyscope.
isItem(node)booleanCheck whether item is a valid tree item.
loadFolds()voidLoad the saved fold states of the tree view from local storage.
onKeyArrowDown(event)voidHandle keyboard event for moving/selecting tree item below.
onKeyArrowLeft(event)voidHandle keyboard event for moving through the hierarchy of tree items (and/or folding/unfolding).
onKeyArrowRight(event)voidHandle keyboard event for moving through the hierarchy of tree items (and/or folding/unfolding).
onKeyArrowUp(event)voidHandle keyboard event for moving/selecting tree item above.
onKeyOpen(event)voidHandle keyboard event for opening tree item.
onResize()voidUpdate scroll representation on resize.
requestSaveFolds()voidRequest saving of the current fold states.
saveFolds()voidSave the current fold states of the tree view to local storage.
selectItem(node)voidMark tree item as selected.
setCollapseAll(collapse)voidSet all items in the tree view to be collapsed or expanded.
setFocusedItem(node, scrollIntoView?)voidSet the focused item in the tree view.
toggleCollapseAll()void(Un)Collapse all items in the tree view.

Links to this page: