Skip to content

Button

KeyAction
EnterClick button
SpaceClick button

When SetDisabled(true), all input is silently ignored.

Button preview

Button is a clickable button component. It wraps button functionality with themed defaults and a cleaner API.

Constructor func NewButton(label string) *Button

Usage

btn := components.NewButton("Save").
SetVariant(components.ButtonPrimary).
SetDisabled(false)
btn.SetOnClick(func() {
fmt.Println("clicked")
})
btn.Click()

Methods

Method Signature Description
Click func (b *Button) Click() Click programmatically triggers the button click.
GetFieldHeight func (b *Button) GetFieldHeight() int GetFieldHeight returns the preferred height for this button.
OnClick func (b *Button) OnClick(handler func()) *Button OnClick is an alias for SetOnClick for a more fluent API.
Primitive func (b *Button) Primitive() *tview.Box Primitive returns the underlying tview.Box for advanced usage.
SetDisabled func (b *Button) SetDisabled(disabled bool) *Button SetDisabled sets whether the button is disabled.
SetLabel func (b *Button) SetLabel(label string) *Button SetLabel sets the button label.
SetOnClick func (b *Button) SetOnClick(handler func()) *Button SetOnClick sets the click handler.
SetVariant func (b *Button) SetVariant(variant ButtonVariant) *Button SetVariant sets the button visual variant.

Types

type ButtonVariant ButtonVariant defines the visual style of a button.
ConstantDescription
ButtonDefault
ButtonPrimary
ButtonSecondary
ButtonDanger
ButtonGhost