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-catalyst-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.
getSelectedItems()T[]Get the items the selection commands act on.
handleCollapseAll()voidHandle collapsing of all nodes.
handleDeleteSelectedItems(event)Promise<void>Handle deletion of selected nodes.
handleItemSelection(event, node)booleanHandle a click on a tree item, applying the Alt-click and Shift-click selection rules.
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.
isKeyboardNavigationEvent(event)booleanCheck whether the event is an ArrowUp or ArrowDown keyboard event.
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.
onKeyEscape(event)voidHandle keyboard event for clearing the selection. Does nothing when no item is selected.
onKeyOpen(event)voidHandle keyboard event for opening tree item.
onResize()voidUpdate scroll representation on resize.
removeSelection(callback)Promise<void>Run an action on each item Tree.getSelectedItems returns, one at a time, deselecting every item it reports as removed and then moving focus to the nearest item that was not part of the selection.
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: