Skip to content

Textarea: multiline input

Build multiline inputs with Textarea. This page includes a runnable example, all props, and behavior constraints.

Complete example

Complete environment setup first. Copy this complete main.go and run go run ..

go
package main

import (
	"github.com/dxui-org/dxui"
	"log"
)

func main() {
	value := "First line\nSecond line"
	app := dxui.NewApp(dxui.AppOptions{
		Title:      "Textarea",
		Width:      640,
		Height:     480,
		Background: dxui.RGBA(248, 250, 252, 255),
	})
	if err := app.Run(func() dxui.View {
		return dxui.Box(
			dxui.BoxProps{
				Gap: 16,
				Style: dxui.Style{
					Padding: dxui.Padding(24),
				},
			},
			dxui.Textarea(dxui.TextareaProps{
				Key:         "notes",
				Value:       value,
				OnChange:    dxui.Assign(&value),
				Wrap:        dxui.TextWrapWords,
				Placeholder: "Notes",
				Style: dxui.Style{
					Width:  dxui.Px(400),
					Height: dxui.Px(180),
				},
			}),
		)
	}); err != nil {

		log.Fatal(err)
	}
}

Parameters and API

go
func Textarea(props TextareaProps) View
FieldTypePurpose, defaults, and constraints
KeystringStable unique identity within one parent; empty by default. Use business IDs in dynamic lists, not changing indices.
StyleStyleLocal layout, paint, and text styling; zero uses intrinsic sizes and theme defaults.
TokenComponentTokenComponent theme entry; empty selects its default.
StatesStateStylesPaint patches for actual interaction states; cannot fabricate state or change layout.
PointerPointerBehaviorDefaults to PointerAuto; PointerNone excludes the entire subtree from pointer participation, unlike Disabled.
ValuestringCurrent application-owned value; see this page for behavior and zero-value semantics.
OnChangefunc(string)Proposes the complete new value; write it to state for the next build. See behavior for nil callbacks.
SelectionOption[TextRange]Unset uses internal selection; Some(TextRange) controls rune-based selection.
OnSelectionChangefunc(TextRange)Proposes a complete rune selection. Nil retains internal selection; controlled Selection takes precedence on rebuild.
PlaceholderstringDisplayed for an empty Value; defaults to empty.
DisabledboolDefaults to false; true removes focus and cancels interaction on interactive components.
ReadOnlyboolDefaults to false; true prevents editing/preedit while preserving navigation and selection.
WrapTextWrapDefaults to TextNoWrap; TextWrapWords uses simple word wrapping.

Behavior and limitations

Uses Input's controlled-value and rune-selection rules. Enter inserts a newline when editable; no OnSubmit, Password, or password toggle. Wrap defaults to TextNoWrap, with TextWrapWords available. Retains internal caret scrolling and undo history. ReadOnly still allows selection, copy, and scrolling. Not a rich-text editor; no grapheme editing or RTL layout.

All components share identity, style, and pointer rules. See full declarations for referenced enums, structs, and comments. Running examples explains build verification.