TextArea
Key bindings
Section titled “Key bindings”TextArea wraps tview.TextArea bindings:
| Key | Action |
|---|---|
Enter | Insert newline |
| Any printable key | Insert character |
Backspace | Delete character |
| Arrow keys | Move cursor |
When inside a Form, Enter passes through to insert newlines. Use Ctrl+S to submit the form.
Form integration
Section titled “Form integration”TextArea implements FormField. The bound value type is string (the full multi-line content).
Usage
area := components.NewTextArea("notes"). SetLabel("Notes"). SetPlaceholder("Write a description..."). SetMaxLines(10). SetValue("first line\nsecond line")area.SetOnChange(func(e *components.ChangeEvent[string]) { fmt.Println("changed:", e.NewValue)})
fmt.Println(area.Value())Methods
| Method | Signature | Description |
|---|---|---|
Clear | func (t *TextArea) Clear() | Clear resets the text area to an empty value. |
ClearField | func (t *TextArea) ClearField() | ClearField resets the field to its zero value. Implements FormField. |
FieldValue | func (t *TextArea) FieldValue() any | FieldValue returns the field's current value as an any. Implements FormField. |
GetFieldHeight | func (t *TextArea) GetFieldHeight() int | GetFieldHeight returns the preferred height for this field. |
GetName | func (t *TextArea) GetName() string | GetName returns the field name. |
GetValue | func (t *TextArea) GetValue() string | GetValue returns the current value. |
HasValue | func (t *TextArea) HasValue() bool | HasValue returns true if the text area has a non-empty value. |
SetFieldValue | func (t *TextArea) SetFieldValue(value any) error | SetFieldValue sets the field's value from an any. Implements FormField. |
SetLabel | func (t *TextArea) SetLabel(label string) *TextArea | SetLabel sets the field label. |
SetMaxLines | func (t *TextArea) SetMaxLines(max int) *TextArea | SetMaxLines sets the maximum number of lines. |
SetOnChange | func (t *TextArea) SetOnChange(handler ChangeHandler[string]) *TextArea | SetOnChange sets the change handler (new API). |
SetPlaceholder | func (t *TextArea) SetPlaceholder(placeholder string) *TextArea | SetPlaceholder sets the placeholder text. |
SetValue | func (t *TextArea) SetValue(value string) *TextArea | SetValue sets the current value. |
Value | func (t *TextArea) Value() string | Value returns the current value (alias for GetValue). This method is part of the ValueProvider interface. |
Types
type ChangeHandler ChangeHandler handles value changes