textfield

package
v0.1.122 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 25 Imported by: 0

README

Textfield

@Composable
fun TextField(
    value: TextFieldValue,
    onValueChange: (TextFieldValue) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    readOnly: Boolean = false,
    textStyle: TextStyle = LocalTextStyle.current,
    label: (@Composable () -> Unit)? = null,
    placeholder: (@Composable () -> Unit)? = null,
    leadingIcon: (@Composable () -> Unit)? = null,
    trailingIcon: (@Composable () -> Unit)? = null,
    prefix: (@Composable () -> Unit)? = null,
    suffix: (@Composable () -> Unit)? = null,
    supportingText: (@Composable () -> Unit)? = null,
    isError: Boolean = false,
    visualTransformation: VisualTransformation = VisualTransformation.None,
    keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
    keyboardActions: KeyboardActions = KeyboardActions.Default,
    singleLine: Boolean = false,
    maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
    minLines: Int = 1,
    interactionSource: MutableInteractionSource? = null,
    shape: Shape = TextFieldDefaults.shape,
    colors: TextFieldColors = TextFieldDefaults.colors()
): Unit

Primary

value: TextFieldValue,
onValueChange: (TextFieldValue) -> Unit,

Optional

modifier: Modifier = Modifier,
enabled: Boolean = true,
readOnly: Boolean = false,
textStyle: TextStyle = LocalTextStyle.current,
label: (@Composable () -> Unit)? = null,
placeholder: (@Composable () -> Unit)? = null,
leadingIcon: (@Composable () -> Unit)? = null,
trailingIcon: (@Composable () -> Unit)? = null,
prefix: (@Composable () -> Unit)? = null,
suffix: (@Composable () -> Unit)? = null,
supportingText: (@Composable () -> Unit)? = null,
isError: Boolean = false,
visualTransformation: VisualTransformation = VisualTransformation.None,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
singleLine: Boolean = false,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
interactionSource: MutableInteractionSource? = null,
shape: Shape = TextFieldDefaults.shape,
colors: TextFieldColors = TextFieldDefaults.colors()

Documentation

Overview

Package textfield contains Material 3 Text Field components.

Reference: [Text Fields](https://m3.material.io/components/text-fields/overview) Specs: [Text Fields Specs](https://m3.material.io/components/text-fields/specs)

Index

Constants

View Source
const Material3OutlinedTextFieldNodeID = "Material3OutlinedTextField"

Variables

This section is empty.

Functions

func WithAlpha

func WithAlpha(c color.NRGBA, a uint8) color.NRGBA

WithAlpha returns the input color with the new alpha value.

Types

type C

type C = layout.Context

type Composable

type Composable = api.Composable

func Outlined

func Outlined(
	value string,
	onValueChange func(string),
	options ...TextFieldOption,
) Composable

Outlined implements the Outlined Material Design 3 text field. It uses a custom widget implementation adapted from gio-x.

type Composer

type Composer = api.Composer

type D

type D = layout.Dimensions

type HandlerWrapper

type HandlerWrapper struct {
	Func func(string)
}

type OnSubmitWrapper

type OnSubmitWrapper struct {
	Func func()
}

type Progress

type Progress struct {
	// contains filtered or unexported fields
}

Progress is an animation primitive that tracks progress of time over a fixed duration as a float between [0, 1].

Progress is reversable.

Widgets map async UI events to state changes: stop, forward, reverse. Widgets then interpolate visual data based on progress value.

Update method must be called every tick to update the progress value.

func (Progress) Absolute

func (p Progress) Absolute() float32

Absolute reports the absolute progress, ignoring direction.

func (Progress) Direction

func (p Progress) Direction() ProgressDirection

Direction reports the current direction.

func (Progress) Finished

func (p Progress) Finished() bool

func (Progress) Progress

func (p Progress) Progress() float32

Progress reports the current progress as a float between [0, 1].

func (*Progress) Start

func (p *Progress) Start(began time.Time, direction ProgressDirection, duration time.Duration)

Start the progress in the given direction over the given duration.

func (Progress) Started

func (p Progress) Started() bool

Started reports true if progression has started.

func (*Progress) Stop

func (p *Progress) Stop()

Stop the progress.

func (*Progress) Update

func (p *Progress) Update(now time.Time)

type ProgressDirection

type ProgressDirection int

ProgressDirection specifies how to update progress every tick.

const (
	// Forward progresses from 0 to 1.
	Forward ProgressDirection = iota
	// Reverse progresses from 1 to 0.
	Reverse
)

func (ProgressDirection) String

func (d ProgressDirection) String() string

type TextEditorConstructorArgs

type TextEditorConstructorArgs struct {
	Editor          *widget.Editor
	Value           string
	Opts            TextFieldOptions
	Handler         *HandlerWrapper
	OnSubmitHandler *OnSubmitWrapper
	Tracker         *TextFieldStateTracker
}

type TextFieldColors

type TextFieldColors struct {
	TextColor                   graphics.Color
	DisabledTextColor           graphics.Color
	CursorColor                 graphics.Color
	ErrorCursorColor            graphics.Color
	SelectionColor              graphics.Color
	FocusedIndicatorColor       graphics.Color
	UnfocusedIndicatorColor     graphics.Color
	DisabledIndicatorColor      graphics.Color
	ErrorIndicatorColor         graphics.Color
	HoveredIndicatorColor       graphics.Color
	LeadingIconColor            graphics.Color
	TrailingIconColor           graphics.Color
	DisabledLeadingIconColor    graphics.Color
	DisabledTrailingIconColor   graphics.Color
	LabelColor                  graphics.Color
	UnfocusedLabelColor         graphics.Color
	DisabledLabelColor          graphics.Color
	ErrorLabelColor             graphics.Color
	PlaceholderColor            graphics.Color
	DisabledPlaceholderColor    graphics.Color
	SupportingTextColor         graphics.Color
	DisabledSupportingTextColor graphics.Color
	ErrorSupportingTextColor    graphics.Color
}

func DefaultTextFieldColors

func DefaultTextFieldColors() TextFieldColors

func ResolveTextFieldColors

func ResolveTextFieldColors(c Composer, colors TextFieldColors) TextFieldColors

type TextFieldComponent

type TextFieldComponent struct {
	// Editor contains the edit buffer.
	widget.Editor

	// Helper text to give additional context to a field.
	Helper string
	// CharLimit specifies the maximum number of characters the text input
	// will allow. Zero means "no limit".
	CharLimit uint
	// Prefix appears before the content of the text input.
	Prefix layout.Widget
	// Suffix appears after the content of the text input.
	Suffix layout.Widget
	// contains filtered or unexported fields
}

TextFieldComponent implements the Material Design Text Field described here: https://material.io/components/text-fields

func (*TextFieldComponent) Clear

func (in *TextFieldComponent) Clear()

Clear the input text and reset any error status.

func (*TextFieldComponent) ClearError

func (in *TextFieldComponent) ClearError()

ClearError clears any errored status.

func (TextFieldComponent) IsActive

func (in TextFieldComponent) IsActive() bool

IsActive if input is in an active state (Active, Focused or Errored).

func (*TextFieldComponent) IsErrored

func (in *TextFieldComponent) IsErrored() bool

IsErrored if input is in an errored state. Typically this is when the validator has returned an error message.

func (*TextFieldComponent) Layout

func (in *TextFieldComponent) Layout(gtx C, th *material.Theme, hint string) D

func (*TextFieldComponent) SetError

func (in *TextFieldComponent) SetError(err string)

SetError puts the input into an errored state with the specified error text.

func (*TextFieldComponent) TextTooLong

func (in *TextFieldComponent) TextTooLong() bool

TextTooLong returns whether the current editor text exceeds the set character limit.

func (*TextFieldComponent) Update

func (in *TextFieldComponent) Update(gtx C, th *material.Theme, hint string)

type TextFieldDecorator

type TextFieldDecorator struct {
	// contains filtered or unexported fields
}

type TextFieldOption

type TextFieldOption func(*TextFieldOptions)

func WithColors

func WithColors(colors TextFieldColors) TextFieldOption

func WithEnabled

func WithEnabled(enabled bool) TextFieldOption

func WithError

func WithError(isError bool) TextFieldOption

func WithLabel

func WithLabel(label string) TextFieldOption

func WithLeadingIcon

func WithLeadingIcon(icon Composable) TextFieldOption

func WithMaxLines

func WithMaxLines(maxLines int) TextFieldOption

func WithMinLines

func WithMinLines(minLines int) TextFieldOption

func WithModifier

func WithModifier(m ui.Modifier) TextFieldOption

func WithOnSubmit

func WithOnSubmit(onSubmit func()) TextFieldOption

func WithPlaceholder

func WithPlaceholder(placeholder string) TextFieldOption

func WithPrefix

func WithPrefix(prefix Composable) TextFieldOption

func WithReadOnly

func WithReadOnly(readOnly bool) TextFieldOption

func WithShape

func WithShape(shape interface{}) TextFieldOption

func WithSingleLine

func WithSingleLine(singleLine bool) TextFieldOption

func WithSuffix

func WithSuffix(suffix Composable) TextFieldOption

func WithSupportingText

func WithSupportingText(text string) TextFieldOption

func WithTextStyle

func WithTextStyle(textStyle *text.TextStyle) TextFieldOption

func WithTrailingIcon

func WithTrailingIcon(icon Composable) TextFieldOption

type TextFieldOptions

type TextFieldOptions struct {
	Modifier       ui.Modifier
	Enabled        bool
	ReadOnly       bool
	TextStyle      *text.TextStyle
	Label          string //maybe.Maybe[api.Composable]
	Placeholder    string //maybe.Maybe[api.Composable]
	LeadingIcon    api.Composable
	TrailingIcon   api.Composable
	Prefix         api.Composable
	Suffix         api.Composable
	SupportingText string //maybe.Maybe[api.Composable]
	IsError        bool
	SingleLine     bool
	MaxLines       int
	MinLines       int

	Shape  interface{}
	Colors TextFieldColors

	OnSubmit func() // Called when Enter is pressed (SingleLine mode)

}

func DefaultTextFieldOptions

func DefaultTextFieldOptions() TextFieldOptions

type TextFieldStateTracker

type TextFieldStateTracker struct {
	LastValue string
}

type TextFieldWidget

type TextFieldWidget struct {
	// Editor contains the edit buffer.
	Editor *widget.Editor

	// Helper text to give additional context to a field.
	Helper string
	// CharLimit specifies the maximum number of characters the text input
	// will allow. Zero means "no limit".
	CharLimit uint
	// Prefix appears before the content of the text input.
	Prefix layout.Widget
	// Suffix appears after the content of the text input.
	Suffix layout.Widget

	Colors TextFieldColors
	// contains filtered or unexported fields
}

TextField implements the Material Design Text Field described here: https://material.io/components/text-fields

func (*TextFieldWidget) Clear

func (in *TextFieldWidget) Clear()

Clear the input text and reset any error status.

func (*TextFieldWidget) ClearError

func (in *TextFieldWidget) ClearError()

ClearError clears any errored status.

func (*TextFieldWidget) IsActive

func (in *TextFieldWidget) IsActive() bool

IsActive if input is in an active state (Active, Focused or Errored).

func (*TextFieldWidget) IsErrored

func (in *TextFieldWidget) IsErrored() bool

IsErrored if input is in an errored state. Typically this is when the validator has returned an error message.

func (*TextFieldWidget) Layout

func (in *TextFieldWidget) Layout(gtx layout.Context, th *material.Theme, hint string) layout.Dimensions

func (*TextFieldWidget) SetError

func (in *TextFieldWidget) SetError(isError bool, err string)

SetError puts the input into an errored state with the specified error text.

func (*TextFieldWidget) TextTooLong

func (in *TextFieldWidget) TextTooLong() bool

TextTooLong returns whether the current editor text exceeds the set character limit.

type Validator

type Validator = func(string) string

Validator validates text and returns a string describing the error. Error is displayed as helper text.

type VisibilityAnimation

type VisibilityAnimation struct {
	// How long does the animation last
	time.Duration
	State   VisibilityAnimationState
	Started time.Time
}

VisibilityAnimation holds the animation state for animations that transition between a "visible" and "invisible" state for a fixed duration of time.

func (VisibilityAnimation) Animating

func (v VisibilityAnimation) Animating() bool

Animating() returns whether the animation is either in the process of appearsing or disappearing.

func (*VisibilityAnimation) Appear

func (v *VisibilityAnimation) Appear(now time.Time)

Appear triggers the animation to begin becoming visible at the provided time. It is a no-op if the animation is already visible.

func (*VisibilityAnimation) Disappear

func (v *VisibilityAnimation) Disappear(now time.Time)

Disappear triggers the animation to begin becoming invisible at the provided time. It is a no-op if the animation is already invisible.

func (*VisibilityAnimation) Revealed

func (v *VisibilityAnimation) Revealed(gtx layout.Context) float32

Revealed returns the fraction of the animated entity that should be revealed at the current time in the animation. This fraction is computed with linear interpolation.

Revealed should be invoked during every frame that v.Animating() returns true.

If the animation reaches its end this frame, Revealed will transition it to a non-animating state automatically.

If the animation is in the process of animating, calling Revealed will automatically add an InvalidateOp to the provided layout.Context to ensure that the next frame will be generated promptly.

func (*VisibilityAnimation) String

func (v *VisibilityAnimation) String(gtx layout.Context) string

func (*VisibilityAnimation) ToggleVisibility

func (v *VisibilityAnimation) ToggleVisibility(now time.Time)

ToggleVisibility will make an invisible animation begin the process of becoming visible and a visible animation begin the process of disappearing.

func (VisibilityAnimation) Visible

func (v VisibilityAnimation) Visible() bool

Visible() returns whether any part of the animated entity should be visible during the current animation frame.

type VisibilityAnimationState

type VisibilityAnimationState int

VisibilityAnimationState represents possible states that a VisibilityAnimation can be in.

const (
	Visible VisibilityAnimationState = iota
	Disappearing
	Appearing
	Invisible
)

func (VisibilityAnimationState) String

func (v VisibilityAnimationState) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL