Skip to main content

TextField

Native text input with decoration, label, and helper text. TextInput is the base native control; TextField wraps it with label, placeholder, and styling.

Basic Usage

// Themed (recommended)
controller := platform.NewTextEditingController("")
theme.TextFieldOf(ctx, controller).
WithLabel("Email").
WithPlaceholder("you@example.com").
WithOnChanged(func(value string) {
s.SetState(func() { email = value })
})

// Explicit (must provide all visual properties)
widgets.TextField{
Controller: controller,
Label: "Email",
Placeholder: "you@example.com",
Height: 48,
Padding: layout.EdgeInsetsSymmetric(12, 8),
BackgroundColor: colors.Surface,
BorderColor: colors.Outline,
FocusColor: colors.Primary,
BorderWidth: 1,
BorderRadius: 8,
Style: graphics.TextStyle{FontSize: 16, Color: colors.OnSurface},
PlaceholderColor: colors.OnSurfaceVariant,
OnChanged: func(value string) {
s.SetState(func() { email = value })
},
}

Properties

PropertyTypeDescription
Controller*platform.TextEditingControllerManages text content and selection
LabelstringLabel text above the field
PlaceholderstringPlaceholder text when empty
HelperTextstringHelper text below the field (hidden when ErrorText is set)
ErrorTextstringError text below the field (overrides HelperText)
Heightfloat64Field height
Paddinglayout.EdgeInsetsInner padding
BackgroundColorgraphics.ColorBackground color
BorderColorgraphics.ColorBorder color
FocusColorgraphics.ColorBorder color when focused
BorderWidthfloat64Border width
BorderRadiusfloat64Corner radius
Stylegraphics.TextStyleText style (font size, color)
PlaceholderColorgraphics.ColorPlaceholder text color
ErrorColorgraphics.ColorError text and border color when ErrorText is set
OnChangedfunc(string)Called when text changes
OnSubmittedfunc(string)Called when the user submits
OnEditingCompletefunc(string)Called with current text when editing is complete
KeyboardTypeplatform.KeyboardTypeKeyboard type (KeyboardTypeEmail, KeyboardTypeNumber, etc.)
InputActionplatform.TextInputActionAction button (TextInputActionNext, TextInputActionDone, etc.)
ObscureboolHide text (for passwords)
AutocorrectboolEnable auto-correction
DisabledboolReject input when true

Explicit Styling Requirements

Explicit text fields only render what you set. If colors, sizes, or text styles are zero, the widget can be invisible or collapsed. You must set Height, Padding, BackgroundColor, BorderColor, FocusColor, BorderWidth, Style (FontSize + Color), and PlaceholderColor.

If you want defaults from the theme, prefer theme.TextFieldOf(ctx, controller).

Common Patterns

Password Field

theme.TextFieldOf(ctx, controller).
WithLabel("Password").
WithPlaceholder("Enter password").
WithObscure(true).
WithInputAction(platform.TextInputActionDone)

Email Field

theme.TextFieldOf(ctx, controller).
WithLabel("Email").
WithPlaceholder("you@example.com").
WithKeyboardType(platform.KeyboardTypeEmail).
WithInputAction(platform.TextInputActionNext)