Skip to content

FileSuggestModal

Unofficial

Base suggest modal for choosing a file, shared by the quick switcher and the mobile “insert file” chooser.

A null suggestion stands for creating a new file named after the query, offered when nothing matches and FileSuggestModal.supportsCreate is true.

Import:

import type { FileSuggestModal } from '@obsidian-typings/obsidian-public-latest';

Signature:

export interface FileSuggestModal extends SuggestModal<FileSuggestModalSuggestion | null>

Extends: SuggestModal<FileSuggestModalSuggestion | null>

Constructor

new FileSuggestModal(app: App)

Constructor.

Properties

PropertyTypeDescription
allowCreateNewFilebooleanWhether the modal may create a new file named after the query.
appAppThe Obsidian app instance.
(Inherited from SuggestModal)
bgElHTMLElementBackground applied to application to dim it
(Inherited from SuggestModal)
bgOpacitystringOpacity percentage of the background
(Inherited from SuggestModal)
chooserSuggestModalChooser<FileSuggestModalSuggestion | null, this>The suggestion chooser that manages selection and rendering.
(Inherited from SuggestModal)
clearButtonElHTMLDivElementButton element to clear the input field.
(Inherited from SuggestModal)
containerElHTMLElementThe container HTML element for the modal.
(Inherited from SuggestModal)
contentElHTMLElementThe HTML element that represents the content of the modal.
(Inherited from SuggestModal)
context'embed' | 'view'Which registry decides whether a non-image attachment extension is offered: view asks the view registry, embed the embed registry.
createButtonElHTMLButtonElementThe "create file" button, shown in the input on mobile while FileSuggestModal.allowCreateNewFile is true.
ctaElHTMLDivElementCall-to-action element displayed in the modal.
(Inherited from SuggestModal)
dimBackgroundbooleanWhether the background is being dimmed
(Inherited from SuggestModal)
emptyStateTextstringThe text to display when there are no suggestions.
(Inherited from SuggestModal)
hasInitialInputFocusbooleanWhether the modal focuses its first input when opened.
(Inherited from SuggestModal)
headerElHTMLDivElementHeader element of the modal dialog.
(Inherited from SuggestModal)
inputElHTMLInputElementThe input element.
(Inherited from SuggestModal)
instructionsElHTMLDivElementElement displaying keyboard shortcut instructions.
(Inherited from SuggestModal)
isAnimatedbooleanWhether the current opening animates, set from Modal.canAnimate on each Modal.open; it also gates swipe-to-dismiss on the header.
(Inherited from SuggestModal)
isOpenbooleanWhether the suggest modal is currently open.
(Inherited from SuggestModal)
limitnumberThe limit of the number of suggestions.
(Inherited from SuggestModal)
modalElHTMLElementThe HTML element that represents the modal.
(Inherited from SuggestModal)
resultContainerElHTMLElementThe result container element.
(Inherited from SuggestModal)
scopeScopeThe scope for the keymaps.
(Inherited from SuggestModal)
selectionnull | WindowSelectionSelection logic handler
(Inherited from SuggestModal)
shouldAnimateOpenbooleanWhether opening the modal should animate.
(Inherited from SuggestModal)
shouldRestoreSelectionbooleanWhether the modal should restore the selection when it is opened or closed.
(Inherited from SuggestModal)
shouldShowAliasbooleanWhether the frontmatter aliases of each file are matched against the query as well.
shouldShowAllTypesbooleanWhether files of every extension are offered, registered or not, when FileSuggestModal.shouldShowNonImageAttachments is true.
shouldShowImagesbooleanWhether image files are offered.
shouldShowMarkdownbooleanWhether Markdown files are offered.
shouldShowNonAttachmentsbooleanWhether canvas and base files are offered.
shouldShowNonFileBookmarksbooleanWhether bookmarks that are not file bookmarks (folders, searches, graphs, URLs) are offered.
shouldShowNonImageAttachmentsbooleanWhether non-image attachments with a registered extension are offered.
shouldShowUnresolvedbooleanWhether the link text of unresolved links is offered.
supportsCreatebooleanWhether creating a new file is offered: FileSuggestModal.allowCreateNewFile and FileSuggestModal.shouldShowMarkdown are both true.
titleElHTMLElementThe HTML element that represents the title of the modal.
(Inherited from SuggestModal)
winnull | WindowReference to the global Window object.
(Inherited from SuggestModal)

Methods

MethodReturnsDescription
animateClose()Promise<void>Performed when animation is complete
(Inherited from SuggestModal)
animateOpen()Promise<void>Performed when animation is started
(Inherited from SuggestModal)
canAnimate()booleanChecks whether this device supports modal animation.
(Inherited from SuggestModal)
canDismiss()booleanChecks whether clicking outside may dismiss the modal.
(Inherited from SuggestModal)
close()voidClose the modal.
(Inherited from SuggestModal)
getRootEl()HTMLElementGets the modal's root element.
(Inherited from SuggestModal)
getSuggestions(query)FileSuggestModalSuggestion[]Gets the suggestions for a query.

The query is trimmed first. An empty query returns the recent files that are offered and not excluded by the user, with a null match. Otherwise every offered vault file is fuzzy-matched by its path (without the .md extension), and, when FileSuggestModal.shouldShowAlias is true, by each of its frontmatter aliases; a file excluded by the user is kept but its score is lowered by 10. Unresolved link text and bookmarks are added when enabled, and the result is sorted by descending score.
onChooseSuggestion(item, evt)voidChoose a suggestion.
(Inherited from SuggestModal)
onClickOutside(evt)voidCloses the modal when a click occurs outside of it, unless the event was already handled.
(Inherited from SuggestModal)
onClose()voidCalled when the modal is closed.
(Inherited from SuggestModal)
onEscapeKey()voidOn escape key press close modal
(Inherited from SuggestModal)
onHistoryBack()voidCalled when the user navigates back in the history.
(Inherited from SuggestModal)
onHistoryForward()voidCalled when the user navigates forward in the history.
(Inherited from SuggestModal)
onInput()voidHandle input change in the suggest modal.
(Inherited from SuggestModal)
onNoSuggestion()voidSet the callback to be called when there are no suggestions.
(Inherited from SuggestModal)
onOpen()Promise<void> | voidCalled when the modal is opened.
(Inherited from SuggestModal)
onSelectedChange(value, evt?)voidCalled after every selection change, including the programmatic one that follows SuggestModalChooser.setSuggestions.
(Inherited from SuggestModal)
onWindowClose()voidOn closing of the modal
(Inherited from SuggestModal)
open()voidShow the modal on the the active window. On phones, the modal will animate on screen.
(Inherited from SuggestModal)
renderSuggestion(value, el)voidRenders a suggestion.
renderSuggestion(value, el)voidRender a suggestion.
(Inherited from SuggestModal)
selectActiveSuggestion(evt)voidSelect the active suggestion.
(Inherited from SuggestModal)
selectSuggestion(value, evt)voidSelect a suggestion.
(Inherited from SuggestModal)
setBackgroundOpacity(opacity)thisSet the background opacity of the dimmed background.
(Inherited from SuggestModal)
setCloseCallback(callback)thisSet the callback to be called when the modal is closed.
(Inherited from SuggestModal)
setContent(content)thisSet the content of the modal.
(Inherited from SuggestModal)
setDimBackground(dim)thisSet whether the background should be dimmed.
(Inherited from SuggestModal)
setInstructions(instructions)voidSet the instructions.
(Inherited from SuggestModal)
setPlaceholder(placeholder)voidSet the placeholder text.
(Inherited from SuggestModal)
setTitle(title)thisSet the title of the modal.
(Inherited from SuggestModal)
updateSuggestions()voidRefresh the displayed suggestions based on the current query.
(Inherited from SuggestModal)

Links to this page: