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

Property Type Description
on boolean The current on/off state of the toggle.
toggleEl HTMLElement The HTML element that represents the toggle.

Methods

Method Returns Description
changeCallback(value) void The function that's called after changing the value of the component.
getValue() boolean Get the value of the toggle.
onChange(callback) this Handle the change event of the toggle.
onClick() void Handle the click event of the toggle.
registerOptionListener(listeners, key) this Register an option listener.
(Inherited from ValueComponent)
setDisabled(disabled) this Disable the toggle.
setSmall() this Renders the toggle in a smaller size.
setTooltip(tooltip, options?) this Set the tooltip of the toggle.
setValue(on) this Set the value of the toggle.
setValue(value) this Set the value of the component.
(Inherited from ValueComponent)

Links to this page: