Skip to content

SuggestModalChooser<T, TOwner>

Unofficial

The component that manages suggestion selection, navigation and rendering for a suggestion owner.

A single runtime class backs both obsidian#SuggestModal’s chooser and obsidian#PopoverSuggest’s suggestions; the owner that constructed it is exposed as SuggestModalChooser.chooser. SuggestionContainer is this same type under the name the popover side uses.

Import:

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

Signature:

export interface SuggestModalChooser<T, TOwner>

Properties

PropertyTypeDescription
chooserTOwnerThe owner that constructed the chooser and renders and selects its suggestions.
containerElHTMLDivElementContainer element the suggestion list is rendered into.
selectedItemnumberIndex of the currently selected suggestion.
selectOnHoverbooleanWhether hovering a suggestion selects it. While false, SuggestModalChooser.onSuggestionMouseover does nothing.
suggestionsHTMLDivElement[]DOM elements for each suggestion row.
valuesnull | T[]Current suggestion values, or null if none.

Methods

MethodReturnsDescription
addMessage(text)HTMLDivElementDisplay a message in the suggestion list.
addSuggestion(value)voidAdd a suggestion value to the list. Does nothing while SuggestModalChooser.values is null.
forceSetSelectedItem(index, evt?)voidSet the selected item by index, scrolling it into view unless a non-keyboard event triggered the change.
getSelectedElement()HTMLDivElement | nullGet the DOM element of the currently selected suggestion.
getSelectedValue()null | TGet the value of the currently selected suggestion.
moveDown(evt)false | voidMove selection to the next suggestion.
moveUp(evt)false | voidMove selection to the previous suggestion.
onSuggestionClick(evt, suggestion)voidHandle click on a suggestion element.
onSuggestionMouseover(evt, suggestion)voidHandle mouseover on a suggestion element. Does nothing while SuggestModalChooser.selectOnHover is false.
pageDown(evt)false | voidMove selection down by one page of visible items.
pageUp(evt)false | voidMove selection up by one page of visible items.
renderSuggestions()voidEmpty the container and re-render one suggestion element per current value, re-applying the selection.
setSelectedItem(index, evt?)voidSet the selected item by index, clamping the index to within the suggestions array, then invoking SuggestModalChooser.forceSetSelectedItem.
setSuggestions(values)voidEmpty the container and replace all suggestions with new values.
shouldSelectOnHover(value)thisSet whether hovering a suggestion selects it.
useSelectedItem(evt)booleanAccept the currently selected suggestion.

Links to this page: