TextArea
Key bindings
Section titled “Key bindings”TextArea provides these key 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. |
GetCursor | func (t *TextArea) GetCursor() (int, int, int, int) | GetCursor returns the cursor position. Since the TextArea has no selection model, the "from" and "to" positions are identical. Returned as (fromRow, fromCol, toRow, toCol) to match the TextArea signature. |
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. |
GetOffset | func (t *TextArea) GetOffset() (int, int) | GetOffset returns the current scroll offset (row, col). |
GetText | func (t *TextArea) GetText() string | GetText returns the full text content (alias for GetValue). |
GetValue | func (t *TextArea) GetValue() string | GetValue returns the current value. |
HandleKey | func (t *TextArea) HandleKey(ev *tcell.EventKey) bool | |
HasValue | func (t *TextArea) HasValue() bool | HasValue returns true if the text area has a non-empty value. |
Replace | func (t *TextArea) Replace(startChar, endChar int, text string) | Replace replaces the rune range [startChar, endChar) in the full text with the given text and positions the cursor immediately after the inserted text. Character positions are rune offsets into the flattened (newline-joined) text. |
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. |
SetText | func (t *TextArea) SetText(text string, cursorAtEnd bool) *TextArea | SetText replaces the content. When cursorAtEnd is true the cursor is placed at the end of the text; otherwise it is reset to the start. |
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