Skip to content

Modal

Official

obsidian#Modal dialog component.

Import:

import { Modal } from 'obsidian';

Signature:

export class Modal implements HistoryHandler

Implements: HistoryHandler

Constructor

new Modal(app: App)

Constructor.

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

Properties

PropertyTypeDescription
appAppThe Obsidian app instance.
bgElHTMLElementBackground applied to application to dim it
bgOpacitystringOpacity percentage of the background
containerElHTMLElementThe container HTML element for the modal.
contentElHTMLElementThe HTML element that represents the content of the modal.
dimBackgroundbooleanWhether the background is being dimmed
hasInitialInputFocusbooleanWhether the modal focuses its first input when opened.
headerElHTMLDivElementHeader element of the modal dialog.
modalElHTMLElementThe HTML element that represents the modal.
scopeScopeThe scope for the keymaps.
selectionnull | WindowSelectionSelection logic handler
shouldAnimatebooleanWhether the modal should animate
shouldRestoreSelectionbooleanWhether the modal should restore the selection when it is opened or closed.
titleElHTMLElementThe HTML element that represents the title of the modal.
winnull | WindowReference to the global Window object.

Methods

MethodReturnsDescription
animateClose()Promise<void>Performed when animation is complete
animateOpen()Promise<void>Performed when animation is started
close()voidClose the modal.
getRootEl()HTMLElementGets the modal's root element.
onClickOutside(evt)voidCloses the modal when a click occurs outside of it, unless the event was already handled.
onClose()voidCalled when the modal is closed.
onEscapeKey()voidOn escape key press close modal
onHistoryBack()voidCalled when the user navigates back in the history.
(Inherited from HistoryHandler)
onHistoryForward()voidCalled when the user navigates forward in the history.
(Inherited from HistoryHandler)
onOpen()Promise<void> | voidCalled when the modal is opened.
onWindowClose()voidOn closing of the modal
open()voidShow the modal on the the active window. On phones, the modal will animate on screen.
setBackgroundOpacity(opacity)thisSet the background opacity of the dimmed background.
setCloseCallback(callback)thisSet the callback to be called when the modal is closed.
setContent(content)thisSet the content of the modal.
setDimBackground(dim)thisSet whether the background should be dimmed.
setTitle(title)thisSet the title of the modal.

Links to this page: