Skip to content

TextField ​

A labeled single-line text input. The label sits above the control; help or error text sits below. Use it for short, free-form values such as names, emails, or passwords.

Import ​

kotlin
import io.github.heartcoolman.prism.ui.PrismTextField

Basic usage ​

kotlin
var text by remember { mutableStateOf("") }
PrismTextField(
    value = text,
    onValueChange = { text = it },
    label = "Email",
    placeholder = "you@example.com",
)

States ​

A non-empty error switches the border and message to danger and replaces helpText. enabled = false renders the disabled style.

kotlin
// Help text below the field
PrismTextField(
    value = text,
    onValueChange = { text = it },
    label = "Username",
    helpText = "Pick a unique handle.",
)

// Error state
PrismTextField(
    value = text,
    onValueChange = { text = it },
    label = "Email",
    error = "Invalid email address.",
)

// Disabled
PrismTextField(
    value = text,
    onValueChange = { text = it },
    label = "Locked",
    enabled = false,
)

Leading icon and password ​

kotlin
PrismTextField(
    value = text,
    onValueChange = { text = it },
    label = "Password",
    leadingIcon = { PrismIcon(PrismIcons.Lock, contentDescription = null, size = 18.dp) },
    visualTransformation = PasswordVisualTransformation(),
)

API ​

ParameterTypeDefaultDescription
valueString—Current text value.
onValueChange(String) -> Unit—Called with the new value on each edit.
modifierModifierModifierLayout modifier applied to the column.
labelString?nullLabel rendered above the input.
placeholderString?nullPlaceholder shown when the value is empty.
helpTextString?nullSupporting text shown below when not in error.
errorString?nullError message; non-empty switches the field to its error state and replaces helpText.
leadingIcon(@Composable () -> Unit)?nullGlyph rendered inside the input, left-aligned.
enabledBooleantrueWhether the field accepts input.
singleLineBooleantrueConstrain the input to a single line.
fullWidthBooleanfalseStretch the field to fill the container width.
keyboardOptionsKeyboardOptionsKeyboardOptions.DefaultSoftware keyboard configuration (type, IME action).
visualTransformationVisualTransformationVisualTransformation.NoneVisual transform applied to the text, e.g. password masking.

Released under the MIT License.