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

Property Type Description
_children Component[] Child Components attached to current component, will be unloaded on unloading parent component.
(Inherited from Component)
_events EventRef[] Events that are attached to the current component, will be detached on unloading parent component.
(Inherited from Component)
_loaded boolean Whether the component and its children are loaded.
(Inherited from Component)
app App The Obsidian app instance.
closeable boolean Whether the leaf may close the view.
containerEl HTMLElement The container HTML element for the component.
icon IconName The icon of the view.
leaf WorkspaceLeaf The leaf of the view.
navigation boolean Whether 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.)
scope null | Scope Assign an optional scope to your view to register hotkeys for when the view is in focus.

Methods

Method Returns Description
addChild(component) T Adds a child component, loading it if this component is loaded.
(Inherited from Component)
close() Promise<void> Closes the view.
getDisplayText() string Get the display text of the view.
getEphemeralState() Record<string, unknown> Get the ephemeral state of the view.
getIcon() IconName Get the icon of the view.
getSideTooltipPlacement() 'left' | 'right' | undefined Returns the placement of the tooltip.
getState() Record<string, unknown> Get the state of the view.
getViewType() string The type of the view.
handleCopy(event) void Handle copy event on metadata editor and serialize properties.
handleCut(event) void Handle cut event on metadata editor and serialize and remove properties.
handlePaste(event) void Handle paste event of properties on metadata editor.
load() void Load this component and its children.
(Inherited from Component)
onClose() Promise<void> Called when the view is closed.
onHeaderMenu(e) void Called when the header context menu is triggered.
onload() void Override this to load your component.
(Inherited from Component)
onOpen() Promise<void> Called when the view is opened.
onPaneMenu(menu, source) void Populates the pane menu.

(Replaces the previously removed onHeaderMenu and onMoreOptionsMenu)
onResize() void Called when the size of this view is changed.
onTabMenu(menu) void Adds the menu items to the menu.
onunload() void Override this to unload your component
(Inherited from Component)
open(parentEl) Promise<void> Opens the view.
register(cb) void Registers a callback to be called when unloading.
(Inherited from Component)
registerDomEvent(el, type, callback, options?) void Registers a DOM event to be detached when unloading.
(Inherited from Component)
registerDomEvent(el, type, callback, options?) void Registers a DOM event to be detached when unloading
(Inherited from Component)
registerDomEvent(el, type, callback, options?) void Registers a DOM event to be detached when unloading
(Inherited from Component)
registerEvent(eventRef) void Registers an event to be detached when unloading.
(Inherited from Component)
registerInterval(id) number Registers 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) void Register a scope keymap event handler to be removed on unload.
(Inherited from Component)
removeChild(component) T Removes a child component, unloading it.
(Inherited from Component)
setEphemeralState(state) void Set the ephemeral state of the view.
setState(state, result) Promise<void> Set the state of the view.
unload() void Override this to unload your component.
(Inherited from Component)

Links to this page: