Setting
Official
A setting.
Import:
import { Setting } from 'obsidian';Signature:
export class SettingConstructor
new Setting(containerEl: HTMLElement)Constructor.
To get the constructor instance, use getSettingConstructor from obsidian-typings/implementations.
Properties
| Property | Type | Description | |
|---|---|---|---|
| components | BaseComponent[] | The components for the setting. | |
| controlEl | HTMLElement | The HTML element for the control. | |
| descEl | HTMLElement | The HTML element for the description. | |
| disabled | boolean | Whether the setting row is disabled. Initialized to false, written only by Setting.setDisabled, and read as its guard by the row-click listener that Setting.setRowClick attaches, so a disabled row does not invoke Setting.rowClick. | |
| errorEl | HTMLElement | null | Error message element shown below the input. Created by setErrorMessage. | |
| iconEl | HTMLDivElement | null | The HTML element for the icon, prepended to Setting.settingEl. Created by Setting.setIcon on its first call, and null until then. | |
| infoEl | HTMLElement | The HTML element for the info. | |
| nameEl | HTMLElement | The HTML element for the name. | |
| rowClick | (() => void) | null | The click handler for the setting row, stored by Setting.setRowClick and invoked by the listener it attaches. null until that first call. | |
| settingEl | HTMLElement | The HTML element for the setting. |
Methods
| Method | Returns | Description | |
|---|---|---|---|
| addButton(cb) | this | Add a button to the setting. | |
| addColorPicker(cb) | this | Add a color picker component to the setting. | |
| addComponent(cb) | this | Add a component to the setting. | |
| addDisplayValue(cb) | this | Add a read-only display value to the row. On a navigable row, this surfaces the value edited on the page the row opens, so the user can see it without opening that page. | |
| addDropdown(cb) | this | Add a dropdown component to the setting. | |
| addExtraButton(cb) | this | Add an extra button to the setting. | |
| addMomentFormat(cb) | this | Add a moment format component to the setting. | |
| addProgressBar(cb) | this | Add a progress bar component to the setting. | |
| addSearch(cb) | this | Add a search component to the setting. | |
| addSlider(cb) | this | Add a slider component to the setting. | |
| addText(cb) | this | Add a text component to the setting. | |
| addTextArea(cb) | this | Add a text area component to the setting. | |
| addToggle(cb) | this | Add a toggle to the setting. | |
| clear() | this | Clear the setting. | |
| setAction(callback) | this | Makes the whole setting row act as a button, invoking the callback when clicked. | |
| setClass(cls) | this | Set the class of the setting. | |
| setDesc(desc) | this | Set the description of the setting. | |
| setDisabled(disabled) | this | Disable the setting. | |
| setErrorMessage(message) | this | Show a persistent validation error message below the setting. Pass an empty string or null to clear it. Adds the is-invalid class to the setting row when a message is present. | |
| setHeading() | this | Make the setting a heading. | |
| setIcon(icon) | this | Set the icon of the setting, shown at the start of the row before the info section. Creates Setting.iconEl on the first call. Passing null or an empty string empties that element instead of removing it. | |
| setName(name) | this | Set the name of the setting. | |
| setName(name) | this | Set the name of the setting. | |
| setNavigable(callback) | this | Makes the setting row navigable (adds a chevron and click handling). | |
| setNoInfo() | this | Hide the info section of the setting. | |
| setRowClick(callback) | void | Make the whole setting row invoke a callback when clicked, storing it in Setting.rowClick. The DOM listener is attached only on the first call, so a later call replaces the handler rather than adding a second one. The stored handler is skipped while the setting is disabled, or when the click has already been default-prevented. Unlike Setting.setNavigable and Setting.setAction, which are both implemented in terms of it, this returns nothing and so does not chain. | |
| setTooltip(tooltip, options?) | this | Set the tooltip of the setting. | |
| setVisibility(visible) | this | Shows/hides the setting. | |
| then(cb) | this | Facilitates chaining. |
Links to this page: