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

Property Type Description
measureEl HTMLSelectElement Hidden select element used to measure the natural width of the dropdown.
measureOptionEl HTMLOptionElement Option element within DropdownComponent.measureEl used for measuring.
selectEl HTMLSelectElement The HTML element representation of the dropdown.

Methods

Method Returns Description
addOption(value, display) this Add an option to the dropdown.
addOptions(options) this Add multiple options to the dropdown.
changeCallback(value) void The function that's called after changing the value of the component.
getValue() string Get the selected value of the dropdown.
onChange(callback) this Set the callback function to be called when the dropdown value changes.
registerOptionListener(listeners, key) this Register an option listener.
(Inherited from ValueComponent)
resizeToFit() void Resizes the dropdown to fit the width of its selected option.
setDisabled(disabled) this Set the disabled state of the dropdown.
setValue(value) this Set the selected value of the dropdown.
setValue(value) this Set the value of the component.
(Inherited from ValueComponent)

Links to this page: