Skip to content

ToggleComponent

Official

A toggle component.

Import:

import { ToggleComponent } from 'obsidian';

Signature:

export class ToggleComponent extends ValueComponent<boolean>

Extends: ValueComponent<boolean>

Constructor

new ToggleComponent(containerEl: HTMLElement)

Constructor.

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

Properties

PropertyTypeDescription
onbooleanThe current on/off state of the toggle.
toggleElHTMLElementThe HTML element that represents the toggle.

Methods

MethodReturnsDescription
changeCallback(value)voidThe function that's called after changing the value of the component.
getValue()booleanGet the value of the toggle.
onChange(callback)thisHandle the change event of the toggle.
onClick()voidHandle the click event of the toggle.
registerOptionListener(listeners, key)thisRegister an option listener.
(Inherited from ValueComponent)
setDisabled(disabled)thisDisable the toggle.
setSmall()thisRenders the toggle in a smaller size.
setTooltip(tooltip, options?)thisSet the tooltip of the toggle.
setValue(on)thisSet the value of the toggle.
setValue(value)thisSet the value of the component.
(Inherited from ValueComponent)

Links to this page: