Skip to content

WorkspaceLeaf

Official

Workspace leaf.

Import:

import { WorkspaceLeaf } from 'obsidian';

Signature:

export class WorkspaceLeaf extends WorkspaceItem implements HoverParent

Extends: WorkspaceItem

Implements: HoverParent

Constructor

new WorkspaceLeaf(app: App, id?: string | undefined)

Constructor.

To get the constructor instance, use getWorkspaceLeafConstructor from obsidian-typings/implementations.

Properties

PropertyTypeDescription
_Record<string, EventsEntry[]>Internal storage of registered event handlers by event name.
(Inherited from WorkspaceItem)
_emptyViewThe cached empty-state view shown when the leaf has no file open.
activeTimenumberTimestamp of when this leaf was last activated.
appAppReference to the app instance.
(Inherited from WorkspaceItem)
componentComponentThe component managing the lifecycle of this workspace item.
(Inherited from WorkspaceItem)
containerElHTMLDivElementContainer element for this workspace item.
(Inherited from WorkspaceItem)
dimensionnull | numberThe flex-grow dimension of this item within its parent split.
(Inherited from WorkspaceItem)
groupnull | stringThe linked group this leaf belongs to, or null if ungrouped.
heightnumberCurrent height of the leaf in pixels.
historyWorkspaceLeafHistoryNavigation history for this leaf (back/forward).
hoverPopoverHoverPopover | nullThe hover popover associated with this leaf.
idstringUnique identifier for this workspace item.
(Inherited from WorkspaceItem)
parentWorkspaceMobileDrawer | WorkspaceTabsThe direct parent of the leaf.

On desktop, a leaf is always a child of a WorkspaceTabs component. On mobile, a leaf might be a child of a WorkspaceMobileDrawer. Perform an instanceof check before making an assumption about the parent.
pinnedbooleanWhether this leaf is pinned (prevented from being navigated away).
resizeHandleElHTMLHRElementThe resize handle element used for adjusting item dimensions.
(Inherited from WorkspaceItem)
resizeObservernull | ResizeObserverObserver that tracks size changes of this leaf.
tabHeaderCloseElHTMLDivElement | nullClose button element in the tab header.
tabHeaderElHTMLElementThe tab header element for this leaf.
tabHeaderInnerIconElHTMLElementIcon element inside the tab header.
tabHeaderInnerTitleElHTMLElementTitle element inside the tab header.
tabHeaderStatusContainerElHTMLDivElement | nullContainer element for tab header status indicators.
tabHeaderStatusLinkElHTMLDivElement | nullStatus element indicating linked group membership in the tab header.
tabHeaderStatusPinElHTMLDivElement | nullStatus element indicating pinned state in the tab header.
type'leaf'The workspace item type identifier for this leaf.
viewViewThe view associated with this leaf. Do not attempt to cast this to your custom obsidian#View without first checking instanceof.
widthnumberCurrent width of the leaf in pixels.
workingbooleanWhether this leaf is currently loading or processing.
workspaceWorkspaceReference to the workspace this item belongs to.
(Inherited from WorkspaceItem)

Methods

MethodReturnsDescription
canNavigate()booleanCheck whether this leaf can be navigated to a different view.
canPin()booleanChecks whether this leaf can be pinned (i.e. its parent is a tab group).
detach()voidDetach this leaf from its parent.
getContainer()WorkspaceContainerGet the root container parent item, which can be one of:. - WorkspaceRoot - WorkspaceWindow
(Inherited from WorkspaceItem)
getDisplayText()stringGet the display text of this leaf.
getEphemeralState()anyGet the ephemeral state of this leaf.
getHistoryState()WorkspaceLeafHistoryStateGet the current navigation history state of this leaf.
getIcon()IconNameGet the icon of this leaf.
getRoot()WorkspaceItemGet the root item.
(Inherited from WorkspaceItem)
getViewState()ViewStateGet the view state of this leaf.
handleDrop(event, draggable, isOver)DropResult | nullHandle a drop event on this leaf.
highlight()voidHighlight this leaf's tab header.
isVisible()booleanCheck whether this leaf is currently visible in the workspace.
loadIfDeferred()Promise<void>If this view is currently deferred, load it and await that it has fully loaded.
off(name, callback)voidRemove an event listener.
(Inherited from WorkspaceItem)
offref(ref)voidRemove an event listener by reference.
(Inherited from WorkspaceItem)
on('pinned-change', callback, ctx?)EventRefHandle the pinned-change event.
on('group-change', callback, ctx?)EventRefHandle the group-change event.
on('history-change', callback, ctx?)EventRefTriggers when the leaf's history gets updated (e.g. when new file is opened, or moving through history).
on('leaf-menu', callback, ctx?)EventRefTriggers when context menu action is executed on the leaf.
on(name, callback, ctx?)EventRefAdd an event listener.
(Inherited from WorkspaceItem)
onOpenTabHeaderMenu(evt, parentEl)voidHandle opening the context menu on this leaf's tab header.
onResize()voidHandle the resize event.
onResizeStart(evt)voidHandle the start of a resize operation on this item.
(Inherited from WorkspaceItem)
open(view)Promise<View>Open a view in this leaf.
openFile(file, openState?)Promise<void>Open a file in this leaf.
openLinkText(linktext, sourcePath, openViewState?)Promise<void>Open a link in the current leaf.
rebuildView()Promise<void>Rebuild the view associated with this leaf.
recordHistory(state)voidRecord a state entry in this leaf's navigation history.
serialize()SerializedWorkspaceItemSerialize this workspace item's state for persistence.
(Inherited from WorkspaceItem)
setDimension(flexgrow?)voidSet the vertical height a leaf may occupy if it is in a split. The height is not set directly, but by setting the flex-grow (css) of the element. This means to predictably affect the height, you also need to use setDimension on the other leafs of the column. (The flex-grow values of every leaf work basically like a ratio, e.g. 1:2 meaning the first leaf takes 33% of the height, and the second 67%.).
setDimension(dimension)voidSet the flex-grow dimension of this item within its parent split.
(Inherited from WorkspaceItem)
setEphemeralState(state)voidSet the ephemeral state of this leaf.
setGroup(group)voidSet the group of this leaf.
setGroupMember(other)voidSet another leaf as a group member of this leaf.
setParent(parent)voidSet the parent split for this workspace item.
(Inherited from WorkspaceItem)
setPinned(pinned)voidSet the pinned state of this leaf.
setViewState(viewState, eState?)Promise<void>Set the view state of this leaf.
togglePinned()voidToggle the pinned state of this leaf.
trigger(name, data?)voidTrigger an event, executing all the listeners in order even if some of them throw an error.
(Inherited from WorkspaceItem)
tryTrigger(evt, args)voidTry to trigger an event, executing all the listeners in order even if some of them throw an error.
(Inherited from WorkspaceItem)
unhighlight()voidRemove highlight from this leaf's tab header.
updateHeader()voidUpdate the tab header display (icon, title, status indicators).

Links to this page: