Skip to content

TypedDropdownComponent<T>

A dropdown component that can be used to select a value from a list.

You can add this component using SettingEx.addTypedDropdown.

In order to add the styles for the component, use initPluginContext in your plugin’s onload() function.

Alternatively, you can copy styles from https://unpkg.com/@mnaoumov/obsidian-lib/dist/styles.css.

Import:

import { TypedDropdownComponent } from '@mnaoumov/obsidian-lib/setting-components/typed-dropdown-component';

Signature:

export class TypedDropdownComponent<T> extends ValueComponent<null | T> implements ValueComponentWithChangeTracking<null | T>

Extends: ValueComponent<null | T>

Implements: ValueComponentWithChangeTracking<null | T>

Constructor

new TypedDropdownComponent(containerEl: HTMLElement)

Creates a new multiple dropdown component.

Properties

PropertyTypeDescription
dropdownComponentDropdownComponentThe inner dropdown component.
onChange(callback: (newValue: null | T) => void) => thisSets a callback function to be called when the value of the component changes.
(Inherited from ValueComponentWithChangeTracking)
valuesT[]The list of selectable option values, indexed by their position in the dropdown.

Methods

MethodReturnsDescription
addOption(value, display)thisAdds an option to the dropdown.
addOptions(options)thisAdds multiple options to the dropdown.
getValue()null | TGets the value of the component.
onChange(callback)thisSets the callback function to be called when the component is changed.
setDisabled(isDisabled)thisSets the disabled state of the component.
setValue(value)thisSets the value of the component.
simulateChange__()voidSimulate a change event.

Links to this page: