CheckboxComponent
A component that displays a checkbox.
You can add this component using SettingEx.addCheckbox.
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 { CheckboxComponent } from '@mnaoumov/obsidian-lib/setting-components/checkbox-component';Signature:
export class CheckboxComponent extends ValueComponent<boolean> implements ValidatorComponent, ValueComponentWithChangeTracking<boolean>Extends: ValueComponent<boolean>
Implements: ValidatorComponent, ValueComponentWithChangeTracking<boolean>
Constructor
new CheckboxComponent(containerEl: HTMLElement)Creates a new checkbox component.
Properties
| Property | Type | Description |
|---|---|---|
| inputEl | HTMLInputElement | An input element of the checkbox. |
| onChange | (callback: (newValue: boolean) => void) => this | Sets a callback function to be called when the value of the component changes. (Inherited from ValueComponentWithChangeTracking) |
| validatorEl | ValidatorElement | A validator element of the component. (Inherited from ValidatorComponent) |
Methods
| Method | Returns | Description |
|---|---|---|
| getValue() | boolean | Gets the value of the checkbox. |
| onChange(callback) | this | Sets the callback to be called when the checkbox is changed. |
| onChanged() | void | Called when the checkbox is changed. |
| setDisabled(isDisabled) | this | Sets the disabled state of the checkbox. |
| setValue(isChecked) | this | Sets the value of the checkbox. |
Links to this page: