Skip to content

ButtonComponent

Official

A button component.

Import:

import { ButtonComponent } from 'obsidian';

Signature:

export class ButtonComponent extends BaseComponent

Extends: BaseComponent

Constructor

new ButtonComponent(containerEl: HTMLElement)

Constructor.

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

Properties

PropertyTypeDescription
buttonElHTMLButtonElementThe HTML element representation of the button.
disabledbooleanWhether the component is disabled.
(Inherited from BaseComponent)

Methods

MethodReturnsDescription
clickCallback()voidThe function that's called after clicking the button.
onClick(callback)thisSets the click event callback for the button component.
removeCta()thisRemoves the call to action style from the button component. CTA stands for call to action.
removeDestructive()thisRemoves the destructive style from the button component.
setButtonText(name)thisSets the text for the button component.
setClass(cls)thisSets the class for the button component.
setCta()thisSets the button component to a call to action button. CTA stands for call to action. It changes how the button is styled, to make it stand out. Use it sparingly, to make the button stand out from others nearby.
setDestructive()thisStyle the button as destructive (e.g. for actions that delete data or are otherwise hard to undo). Compose with setCta for a destructive primary action.
setDisabled(disabled)thisSets the disabled state of the button component.
setIcon(icon)thisSets the icon for the button component.
setLoading(loading)thisToggles the button's loading state.
setTooltip(tooltip, options?)thisSets the tooltip for the button component.
setWarning()thisSets the button component to a warning button. Usually it's added to buttons that perform destructive actions, such as deleting user's data.
then(cb)thisFacilitates chaining.
(Inherited from BaseComponent)

Links to this page: