Skip to content

DropdownComponent

Official

Dropdown component

Import:

import { DropdownComponent } from 'obsidian';

Signature:

export class DropdownComponent extends ValueComponent<string>

Extends: ValueComponent<string>

Constructor

new DropdownComponent(containerEl: HTMLElement)

Constructor.

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

Properties

PropertyTypeDescription
measureElHTMLSelectElementHidden select element used to measure the natural width of the dropdown.
measureOptionElHTMLOptionElementOption element within DropdownComponent.measureEl used for measuring.
selectElHTMLSelectElementThe HTML element representation of the dropdown.

Methods

MethodReturnsDescription
addOption(value, display)thisAdd an option to the dropdown.
addOptions(options)thisAdd multiple options to the dropdown.
changeCallback(value)voidThe function that's called after changing the value of the component.
getValue()stringGet the selected value of the dropdown.
onChange(callback)thisSet the callback function to be called when the dropdown value changes.
registerOptionListener(listeners, key)thisRegister an option listener.
(Inherited from ValueComponent)
resizeToFit()voidResizes the dropdown to fit the width of its selected option.
setDisabled(disabled)thisSet the disabled state of the dropdown.
setValue(value)thisSet the selected value of the dropdown.
setValue(value)thisSet the value of the component.
(Inherited from ValueComponent)

Links to this page: