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

Property Type Description
_ Record<string, EventsEntry[]> Internal storage of registered event handlers by event name.
(Inherited from WorkspaceItem)
_empty View The cached empty-state view shown when the leaf has no file open.
activeTime number Timestamp of when this leaf was last activated.
app App Reference to the app instance.
(Inherited from WorkspaceItem)
component Component The component managing the lifecycle of this workspace item.
(Inherited from WorkspaceItem)
containerEl HTMLDivElement Container element for this workspace item.
(Inherited from WorkspaceItem)
dimension null | number The flex-grow dimension of this item within its parent split.
(Inherited from WorkspaceItem)
group null | string The linked group this leaf belongs to, or null if ungrouped.
height number Current height of the leaf in pixels.
history WorkspaceLeafHistory Navigation history for this leaf (back/forward).
hoverPopover HoverPopover | null The hover popover associated with this leaf.
id string Unique identifier for this workspace item.
(Inherited from WorkspaceItem)
parent WorkspaceMobileDrawer | WorkspaceTabs The 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.
pinned boolean Whether this leaf is pinned (prevented from being navigated away).
resizeHandleEl HTMLHRElement The resize handle element used for adjusting item dimensions.
(Inherited from WorkspaceItem)
resizeObserver null | ResizeObserver Observer that tracks size changes of this leaf.
tabHeaderCloseEl HTMLDivElement | null Close button element in the tab header.
tabHeaderEl HTMLElement The tab header element for this leaf.
tabHeaderInnerIconEl HTMLElement Icon element inside the tab header.
tabHeaderInnerTitleEl HTMLElement Title element inside the tab header.
tabHeaderStatusContainerEl HTMLDivElement | null Container element for tab header status indicators.
tabHeaderStatusLinkEl HTMLDivElement | null Status element indicating linked group membership in the tab header.
tabHeaderStatusPinEl HTMLDivElement | null Status element indicating pinned state in the tab header.
type 'leaf' The workspace item type identifier for this leaf.
view View The view associated with this leaf. Do not attempt to cast this to your custom obsidian#View without first checking instanceof.
width number Current width of the leaf in pixels.
working boolean Whether this leaf is currently loading or processing.
workspace Workspace Reference to the workspace this item belongs to.
(Inherited from WorkspaceItem)

Methods

Method Returns Description
canNavigate() boolean Check whether this leaf can be navigated to a different view.
canPin() boolean Checks whether this leaf can be pinned (i.e. its parent is a tab group).
detach() void Detach this leaf from its parent.
getContainer() WorkspaceContainer Get the root container parent item, which can be one of:. - WorkspaceRoot - WorkspaceWindow
(Inherited from WorkspaceItem)
getDisplayText() string Get the display text of this leaf.
getEphemeralState() any Get the ephemeral state of this leaf.
getHistoryState() WorkspaceLeafHistoryState Get the current navigation history state of this leaf.
getIcon() IconName Get the icon of this leaf.
getRoot() WorkspaceItem Get the root item.
(Inherited from WorkspaceItem)
getViewState() ViewState Get the view state of this leaf.
handleDrop(event, draggable, isOver) DropResult | null Handle a drop event on this leaf.
highlight() void Highlight this leaf's tab header.
isVisible() boolean Check 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) void Remove an event listener.
(Inherited from WorkspaceItem)
offref(ref) void Remove an event listener by reference.
(Inherited from WorkspaceItem)
on('pinned-change', callback, ctx?) EventRef Handle the pinned-change event.
on('group-change', callback, ctx?) EventRef Handle the group-change event.
on('history-change', callback, ctx?) EventRef Triggers when the leaf's history gets updated (e.g. when new file is opened, or moving through history).
on('leaf-menu', callback, ctx?) EventRef Triggers when context menu action is executed on the leaf.
on(name, callback, ctx?) EventRef Add an event listener.
(Inherited from WorkspaceItem)
onOpenTabHeaderMenu(evt, parentEl) void Handle opening the context menu on this leaf's tab header.
onResize() void Handle the resize event.
onResizeStart(evt) void Handle 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) void Record a state entry in this leaf's navigation history.
serialize() SerializedWorkspaceItem Serialize this workspace item's state for persistence.
(Inherited from WorkspaceItem)
setDimension(flexgrow?) void Set 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) void Set the flex-grow dimension of this item within its parent split.
(Inherited from WorkspaceItem)
setEphemeralState(state) void Set the ephemeral state of this leaf.
setGroup(group) void Set the group of this leaf.
setGroupMember(other) void Set another leaf as a group member of this leaf.
setParent(parent) void Set the parent split for this workspace item.
(Inherited from WorkspaceItem)
setPinned(pinned) void Set the pinned state of this leaf.
setViewState(viewState, eState?) Promise<void> Set the view state of this leaf.
togglePinned() void Toggle the pinned state of this leaf.
trigger(name, data?) void Trigger an event, executing all the listeners in order even if some of them throw an error.
(Inherited from WorkspaceItem)
tryTrigger(evt, args) void Try to trigger an event, executing all the listeners in order even if some of them throw an error.
(Inherited from WorkspaceItem)
unhighlight() void Remove highlight from this leaf's tab header.
updateHeader() void Update the tab header display (icon, title, status indicators).

Links to this page: