Skip to content

View

Official

Base class for all views.

Import:

import { View } from 'obsidian';

Signature:

export class View extends Component

Extends: Component

Constructor

new View(leaf: WorkspaceLeaf)

Constructor.

To extract the constructor type, use ExtractConstructor<View>.

Properties

PropertyTypeDescription
_childrenComponent[]Child Components attached to current component, will be unloaded on unloading parent component.
(Inherited from Component)
_eventsEventRef[]Events that are attached to the current component, will be detached on unloading parent component.
(Inherited from Component)
_loadedbooleanWhether the component and its children are loaded.
(Inherited from Component)
appAppThe Obsidian app instance.
closeablebooleanWhether the leaf may close the view.
containerElHTMLElementThe container HTML element for the component.
iconIconNameThe icon of the view.
leafWorkspaceLeafThe leaf of the view.
navigationbooleanWhether or not the view is intended for navigation. If your view is a static view that is not intended to be navigated away, set this to false. (For example: File explorer, calendar, etc.) If your view opens a file or can be otherwise navigated, set this to true. (For example: Markdown editor view, Kanban view, PDF view, etc.)
scopenull | ScopeAssign an optional scope to your view to register hotkeys for when the view is in focus.

Methods

MethodReturnsDescription
addChild(component)TAdds a child component, loading it if this component is loaded.
(Inherited from Component)
close()Promise<void>Closes the view.
getDisplayText()stringGet the display text of the view.
getEphemeralState()Record<string, unknown>Get the ephemeral state of the view.
getIcon()IconNameGet the icon of the view.
getSideTooltipPlacement()'left' | 'right' | undefinedReturns the placement of the tooltip.
getState()Record<string, unknown>Get the state of the view.
getViewType()stringThe type of the view.
handleCopy(event)voidHandle copy event on metadata editor and serialize properties.
handleCut(event)voidHandle cut event on metadata editor and serialize and remove properties.
handlePaste(event)voidHandle paste event of properties on metadata editor.
load()voidLoad this component and its children.
(Inherited from Component)
onClose()Promise<void>Called when the view is closed.
onHeaderMenu(e)voidCalled when the header context menu is triggered.
onload()voidOverride this to load your component.
(Inherited from Component)
onOpen()Promise<void>Called when the view is opened.
onPaneMenu(menu, source)voidPopulates the pane menu.

(Replaces the previously removed onHeaderMenu and onMoreOptionsMenu)
onResize()voidCalled when the size of this view is changed.
onTabMenu(menu)voidAdds the menu items to the menu.
onunload()voidOverride this to unload your component
(Inherited from Component)
open(parentEl)Promise<void>Opens the view.
register(cb)voidRegisters a callback to be called when unloading.
(Inherited from Component)
registerDomEvent(el, type, callback, options?)voidRegisters a DOM event to be detached when unloading.
(Inherited from Component)
registerDomEvent(el, type, callback, options?)voidRegisters a DOM event to be detached when unloading
(Inherited from Component)
registerDomEvent(el, type, callback, options?)voidRegisters a DOM event to be detached when unloading
(Inherited from Component)
registerEvent(eventRef)voidRegisters an event to be detached when unloading.
(Inherited from Component)
registerInterval(id)numberRegisters an interval (from setInterval) to be cancelled when unloading. Use window.setInterval instead of setInterval to avoid TypeScript confusing between NodeJS vs Browser API
(Inherited from Component)
registerScopeEvent(keymapEventHandler)voidRegister a scope keymap event handler to be removed on unload.
(Inherited from Component)
removeChild(component)TRemoves a child component, unloading it.
(Inherited from Component)
setEphemeralState(state)voidSet the ephemeral state of the view.
setState(state, result)Promise<void>Set the state of the view.
unload()voidOverride this to unload your component.
(Inherited from Component)

Links to this page: