Skip to content

Lifecycle

Every dado component follows the same four-phase lifecycle.

Instantiate with the New constructor:

badge := components.NewBadge()
grid := components.NewDataGrid()
modal := components.NewModal()

Constructors return a fully initialised component with sensible defaults. No options are required.

Chain Set* methods before mounting:

badge.
SetLabel("OK").
SetVariant(components.BadgeVariantSuccess)

All Set* methods return the receiver so chains compose cleanly.

Components satisfy tview.Primitive, so they slot directly into tview layouts with no adapter code:

flex := tview.NewFlex().
AddItem(sidebar, 24, 0, false).
AddItem(grid, 0, 1, true)

That layout becomes visible by living inside a view that you push onto the app’s page stack. See Views & Navigation for how to wrap components in a view and move between screens.

Wire callbacks after constructing:

grid.OnActivate(func(row int) { … })
form.OnSubmit(func(e components.SubmitEvent) { … })
input.OnChange(func(e components.ChangeEvent) { … })

Callbacks are called on the tview goroutine. For background work use app.QueueUpdateDraw to push updates back to the UI thread.

All dado widgets embed one of these two base types:

BaseWhen used
ComponentBaseStateless display components (Badge, Spinner, …)
StatefulComponentBaseComponents with mutable internal state (DataGrid, Form, …)

You rarely interact with these directly, but they appear in the API docs as the source of shared methods (SetBorder, SetTitle, SetTheme, …).

dado components have no explicit teardown. When a component is removed from the view tree and goes out of scope the Go garbage collector reclaims it. Long-lived background goroutines spawned inside a component should be stopped explicitly before unmounting.