Skip to content

Events

dado components surface user interactions through typed event structs. Every event embeds BaseEvent which carries the source component.

TypeFired when
ActivateEventUser selects/activates an item (Enter key)
ChangeEventA value changes (text input, select, …)
FocusEventA component gains or loses focus
KeyEventA raw key press reaches a component
SubmitEventA form or input is submitted

Each event type has a corresponding On* method:

input.OnChange(func(e components.ChangeEvent) {
fmt.Println("new value:", e.Value)
})
form.OnSubmit(func(e components.SubmitEvent) {
values := e.Values // map[string]string
})
grid.OnActivate(func(row int) {
// row is the zero-based selected row index
})
component.OnFocus(func(e components.FocusEvent) {
fmt.Println("gained focus:", e.Gained)
})

All event structs embed BaseEvent:

type BaseEvent struct {
Source tview.Primitive // the component that emitted the event
}

Event callbacks run on the tview draw goroutine. If your callback performs slow or blocking work, hand it off to a separate goroutine and use app.QueueUpdateDraw to push UI updates back:

grid.OnActivate(func(row int) {
go func() {
result := fetchDetails(row)
app.QueueUpdateDraw(func() {
detail.SetText(result)
})
}()
})