TextField

fun TextField(value: String, onValueChange: (String) -> Unit, editable: Boolean = true, modifier: Modifier = Modifier, contentPadding: PaddingValues = NoPadding, leadingIcon: @Composable () -> Unit? = null, trailingIcon: @Composable () -> Unit? = null, placeholder: String = "", contentColor: Color = LocalContentColor.current, disabledColor: Color = contentColor.copy(0.66f), backgroundColor: Color = Color.Unspecified, borderWidth: Dp = 1.dp, borderColor: Color = Color.Unspecified, shape: Shape = RectangleShape, textStyle: TextStyle = LocalTextStyle.current, textAlign: TextAlign = TextAlign.Unspecified, fontSize: TextUnit = TextUnit.Unspecified, fontWeight: FontWeight? = null, fontFamily: FontFamily? = null, singleLine: Boolean = false, minLines: Int = 1, maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE, keyboardOptions: KeyboardOptions = KeyboardOptions.Default, keyboardActions: KeyboardActions = KeyboardActions.Default, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, spacing: Dp = 8.dp, visualTransformation: VisualTransformation = VisualTransformation.None, verticalAlignment: Alignment.Vertical = Alignment.CenterVertically)

A foundational component used to build text fields.

For interactive preview & code examples, visit Text Field Documentation.

Basic Example

var text by remember { mutableStateOf("") }

TextField(
value = text,
onValueChange = { text = it },
placeholder = "Enter text",
shape = RoundedCornerShape(8.dp),
backgroundColor = Color.White,
borderColor = Color(0xFFE4E4E4),
borderWidth = 1.dp
)

Parameters

value

The input text to be shown in the text field.

onValueChange

The callback that is triggered when the input service updates the text.

editable

Whether the text field is editable.

modifier

Modifier to be applied to the text field.

contentPadding

Padding values for the content.

leadingIcon

Optional composable to be shown at the start of the text field.

trailingIcon

Optional composable to be shown at the end of the text field.

placeholder

The placeholder composable to be shown when the text field is empty.

contentColor

The color of the text.

disabledColor

The color of the text when the text field is disabled.

backgroundColor

The background color of the text field.

borderWidth

The width of the border.

borderColor

The color of the border.

shape

The shape of the text field.

textStyle

The style of the text.

textAlign

The alignment of the text.

fontSize

The size of the text.

fontWeight

The weight of the text.

fontFamily

The font family of the text.

singleLine

Whether the text field should be constrained to a single line.

minLines

The minimum number of lines to be shown.

maxLines

The maximum number of lines to be shown.

keyboardOptions

The keyboard options for the text field.

keyboardActions

The keyboard actions for the text field.

interactionSource

The interaction source for the text field.

spacing

The spacing between the leading icon, text, and trailing icon.

visualTransformation

The visual transformation to be applied to the text.

verticalAlignment

The vertical alignment of the content.