Object

TextFieldDefaults

Contains the default values used by TextField.

RevenueCat

RevenueCat

Add subscriptions to your apps in minutes

Ad Get started for free
Common
object TextFieldDefaults

Contains the default values used by TextField. For defaults used in OutlinedTextField, see OutlinedTextFieldDefaults.

Properties

Common
val shape: Shape

Default shape for a TextField.

Common
val MinHeight = 56.dp

The default min height applied to a TextField. Note that you can override it by applying Modifier.heightIn directly on a text field.

Common
val MinWidth = 280.dp

The default min width applied to a TextField. Note that you can override it by applying Modifier.widthIn directly on a text field.

Common
val UnfocusedIndicatorThickness = 1.dp

The default thickness of the indicator line in TextField in unfocused state.

Common
val FocusedIndicatorThickness = 2.dp

The default thickness of the indicator line in TextField in focused state.

Common
Deprecated Renamed to OutlinedTextFieldDefaults.shape
val outlinedShape: Shape
Common
Deprecated Renamed to TextFieldDefaults.shape
val filledShape: Shape
Common
Deprecated Split into TextFieldDefaults.UnfocusedIndicatorThickness and OutlinedTextFieldDefaults.UnfocusedBorderThickness. Please update as appropriate.
val UnfocusedBorderThickness = UnfocusedIndicatorThickness
Common
Deprecated Split into TextFieldDefaults.FocusedIndicatorThickness and OutlinedTextFieldDefaults.FocusedBorderThickness. Please update as appropriate.
val FocusedBorderThickness = FocusedIndicatorThickness

Functions

decorator

@Composable
    fun decorator(
        state: TextFieldState,
        enabled: Boolean,
        lineLimits: TextFieldLineLimits,
        outputTransformation: OutputTransformation?,
        interactionSource: InteractionSource,
        labelPosition: TextFieldLabelPosition = TextFieldLabelPosition.Attached(),
        label: @Composable (TextFieldLabelScope.() -> 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,
        colors: TextFieldColors = colors(),
        contentPadding: PaddingValues =
            if (label == null || labelPosition is TextFieldLabelPosition.Above) {
                contentPaddingWithoutLabel()
            } else {
                contentPaddingWithLabel()
            },
        container: @Composable () -> Unit = {
            Container(
                enabled = enabled,
                isError = isError,
                interactionSource = interactionSource,
                colors = colors,
                shape = shape,
                focusedIndicatorLineThickness = FocusedIndicatorThickness,
                unfocusedIndicatorLineThickness = UnfocusedIndicatorThickness,
            )
        },
    ): TextFieldDecorator

A decorator used to create custom text fields based on Material Design filled text field.

If your text field requires customising elements that aren't exposed by TextField, such as the indicator line thickness, consider using this decorator to achieve the desired design.

For example, if you wish to customise the bottom indicator line, you can pass a custom Container to this decorator's container.

This decorator is meant to be used in conjunction with the overload of BasicTextField that accepts a TextFieldDecorator parameter. For other overloads of BasicTextField that use a decorationBox, see DecorationBox.

An example of building a custom text field using decorator:

Parameters

state TextFieldState object that holds the internal editing state of the text field.
enabled the enabled state of the text field. When false, this decorator will appear visually disabled. This must be the same value that is passed to BasicTextField.
lineLimits whether the text field is SingleLine or MultiLine. This must be the same value that is passed to BasicTextField.
outputTransformation OutputTransformation that transforms how the contents of the text field are presented. This must be the same value that is passed to BasicTextField.
interactionSource the read-only InteractionSource representing the stream of Interactions for this text field. You must first create and pass in your own remembered MutableInteractionSource instance to the BasicTextField for it to dispatch events. And then pass the same instance to this decorator to observe Interactions and customize the appearance/behavior of the text field in different states.
labelPosition the position of the label. See TextFieldLabelPosition.
label the optional label to be displayed with this text field. The default text style uses Typography.bodySmall when minimized and Typography.bodyLarge when expanded.
placeholder the optional placeholder to be displayed when the input text is empty. The default text style uses Typography.bodyLarge.
leadingIcon the optional leading icon to be displayed at the beginning of the text field container.
trailingIcon the optional trailing icon to be displayed at the end of the text field container.
prefix the optional prefix to be displayed before the input text in the text field.
suffix the optional suffix to be displayed after the input text in the text field.
supportingText the optional supporting text to be displayed below the text field.
isError indicates if the text field's current value is in an error state. When true, this decorator will display its contents in an error color.
colors TextFieldColors that will be used to resolve the colors used for this text field decorator in different states. See TextFieldDefaults.colors. Note: This parameter only affects the colors of elements in the decoration box. Elements of the BasicTextField (such as text color or cursor color) are unaffected and must be changed using the relevant parameters of BasicTextField.
contentPadding the padding between the input field and the surrounding elements of the decorator. Note that the padding values may not be respected if they are incompatible with the text field's size constraints or layout. See TextFieldDefaults.contentPaddingWithLabel and TextFieldDefaults.contentPaddingWithoutLabel.
container the container to be drawn behind the text field. By default, this uses Container. Default colors for the container come from the colors.

Container

@Composable
    fun Container(
        enabled: Boolean,
        isError: Boolean,
        interactionSource: InteractionSource,
        modifier: Modifier = Modifier,
        colors: TextFieldColors = colors(),
        shape: Shape = TextFieldDefaults.shape,
        focusedIndicatorLineThickness: Dp = FocusedIndicatorThickness,
        unfocusedIndicatorLineThickness: Dp = UnfocusedIndicatorThickness,
    )

Composable that draws a default container for a TextField with an indicator line at the bottom. You can apply it to a BasicTextField using decorator or DecorationBox to create a custom text field based on the styling of a Material filled text field. The TextField component applies it automatically.

Parameters

enabled whether the text field is enabled
isError whether the text field's current value is in error
interactionSource the InteractionSource of the text field. Used to determine if the text field is in focus or not
modifier the Modifier of this container
colors TextFieldColors used to resolve colors of the text field
shape the shape of this container
focusedIndicatorLineThickness thickness of the indicator line when the text field is focused
unfocusedIndicatorLineThickness thickness of the indicator line when the text field is not focused

indicatorLine

fun Modifier.indicatorLine(
        enabled: Boolean,
        isError: Boolean,
        interactionSource: InteractionSource,
        colors: TextFieldColors? = null,
        textFieldShape: Shape? = null,
        focusedIndicatorLineThickness: Dp = FocusedIndicatorThickness,
        unfocusedIndicatorLineThickness: Dp = UnfocusedIndicatorThickness,
    ) =
        this then
            IndicatorLineElement(
                enabled = enabled,
                isError = isError,
                interactionSource = interactionSource,
                colors = colors,
                textFieldShape = textFieldShape,
                focusedIndicatorLineThickness = focusedIndicatorLineThickness,
                unfocusedIndicatorLineThickness = unfocusedIndicatorLineThickness,
            )

A modifier to draw a default bottom indicator line for TextField. You can apply it to a BasicTextField to create a custom text field based on the styling of a Material filled text field.

Consider using Container, which automatically applies this modifier as well as other text field container styling.

Parameters

enabled whether the text field is enabled
isError whether the text field's current value is in error
interactionSource the InteractionSource of the text field. Used to determine if the text field is in focus or not
colors TextFieldColors used to resolve colors of the text field. If null, defaults to TextFieldDefaults.colors.
textFieldShape the shape of the text field container. Used for clipping the indicator. If null, defaults to TextFieldDefaults.shape.
focusedIndicatorLineThickness thickness of the indicator line when the text field is focused
unfocusedIndicatorLineThickness thickness of the indicator line when the text field is not focused

DecorationBox

@Composable
    fun DecorationBox(
        value: String,
        innerTextField: @Composable () -> Unit,
        enabled: Boolean,
        singleLine: Boolean,
        visualTransformation: VisualTransformation,
        interactionSource: InteractionSource,
        isError: Boolean = false,
        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,
        shape: Shape = TextFieldDefaults.shape,
        colors: TextFieldColors = colors(),
        contentPadding: PaddingValues =
            if (label == null) {
                contentPaddingWithoutLabel()
            } else {
                contentPaddingWithLabel()
            },
        container: @Composable () -> Unit = {
            Container(
                enabled = enabled,
                isError = isError,
                interactionSource = interactionSource,
                modifier = Modifier,
                colors = colors,
                shape = shape,
                focusedIndicatorLineThickness = FocusedIndicatorThickness,
                unfocusedIndicatorLineThickness = UnfocusedIndicatorThickness,
            )
        },
    )

A decoration box used to create custom text fields based on Material Design filled text field.

If your text field requires customising elements that aren't exposed by TextField, consider using this decoration box to achieve the desired design.

For example, if you wish to customise the bottom indicator line, you can pass a custom Container to this decoration box's container.

This decoration box is meant to be used in conjunction with overloads of BasicTextField that accept a decorationBox parameter. For other overloads of BasicTextField that use a TextFieldDecorator, see decorator.

An example of building a custom text field using DecorationBox:

Parameters

value the input String shown by the text field
innerTextField input text field that this decoration box wraps. Pass the framework-controlled composable parameter innerTextField from the decorationBox lambda of the BasicTextField
enabled the enabled state of the text field. When false, this decoration box will appear visually disabled. This must be the same value that is passed to BasicTextField.
singleLine indicates if this is a single line or multi line text field. This must be the same value that is passed to BasicTextField.
visualTransformation transforms the visual representation of the input value. This must be the same value that is passed to BasicTextField.
interactionSource the read-only InteractionSource representing the stream of Interactions for this text field. You must first create and pass in your own remembered MutableInteractionSource instance to the BasicTextField for it to dispatch events. And then pass the same instance to this decoration box to observe Interactions and customize the appearance / behavior of this text field in different states.
isError indicates if the text field's current value is in an error state. When true, this decoration box will display its contents in an error color.
label the optional label to be displayed with this text field. The default text style uses Typography.bodySmall when minimized and Typography.bodyLarge when expanded.
placeholder the optional placeholder to be displayed when the text field is in focus and the input text is empty. The default text style for internal Text is Typography.bodyLarge.
leadingIcon the optional leading icon to be displayed at the beginning of the text field container
trailingIcon the optional trailing icon to be displayed at the end of the text field container
prefix the optional prefix to be displayed before the input text in the text field
suffix the optional suffix to be displayed after the input text in the text field
supportingText the optional supporting text to be displayed below the text field
shape defines the shape of this decoration box's container
colors TextFieldColors that will be used to resolve the colors used for this text field decoration box in different states. See TextFieldDefaults.colors. Note: This parameter only affects the colors of elements in the decoration box. Elements of the BasicTextField (such as text color or cursor color) are unaffected and must be changed using the relevant parameters of BasicTextField.
contentPadding the padding between the input field and the surrounding elements of the decoration box. Note that the padding values may not be respected if they are incompatible with the text field's size constraints or layout. See TextFieldDefaults.contentPaddingWithLabel and TextFieldDefaults.contentPaddingWithoutLabel.
container the container to be drawn behind the text field. By default, this uses Container. Default colors for the container come from the colors.

contentPaddingWithLabel

fun contentPaddingWithLabel(
        start: Dp = TextFieldPadding,
        end: Dp = TextFieldPadding,
        top: Dp = TextFieldWithLabelVerticalPadding,
        bottom: Dp = TextFieldWithLabelVerticalPadding,
    ): PaddingValues

Default content padding of the input field within the TextField when there is an inside label. Note that the top padding represents the padding above the label in the focused state. The input field is placed directly beneath the label.

Horizontal padding represents the distance between the input field and the leading/trailing icons (if present) or the horizontal edges of the container if there are no icons.


contentPaddingWithoutLabel

fun contentPaddingWithoutLabel(
        start: Dp = TextFieldPadding,
        top: Dp = TextFieldPadding,
        end: Dp = TextFieldPadding,
        bottom: Dp = TextFieldPadding,
    ): PaddingValues

Default content padding of the input field within the TextField when the label is null or positioned TextFieldLabelPosition.Above.

Horizontal padding represents the distance between the input field and the leading/trailing icons (if present) or the horizontal edges of the container if there are no icons.


colors

@Composable
    fun colors() =
        MaterialTheme.colorScheme.defaultTextFieldColors(LocalTextSelectionColors.current)

Creates a TextFieldColors that represents the default input text, container, and content colors (including label, placeholder, icons, etc.) used in a TextField.


colors

@Composable
    fun colors(
        focusedTextColor: Color = Color.Unspecified,
        unfocusedTextColor: Color = Color.Unspecified,
        disabledTextColor: Color = Color.Unspecified,
        errorTextColor: Color = Color.Unspecified,
        focusedContainerColor: Color = Color.Unspecified,
        unfocusedContainerColor: Color = Color.Unspecified,
        disabledContainerColor: Color = Color.Unspecified,
        errorContainerColor: Color = Color.Unspecified,
        cursorColor: Color = Color.Unspecified,
        errorCursorColor: Color = Color.Unspecified,
        selectionColors: TextSelectionColors? = null,
        focusedIndicatorColor: Color = Color.Unspecified,
        unfocusedIndicatorColor: Color = Color.Unspecified,
        disabledIndicatorColor: Color = Color.Unspecified,
        errorIndicatorColor: Color = Color.Unspecified,
        focusedLeadingIconColor: Color = Color.Unspecified,
        unfocusedLeadingIconColor: Color = Color.Unspecified,
        disabledLeadingIconColor: Color = Color.Unspecified,
        errorLeadingIconColor: Color = Color.Unspecified,
        focusedTrailingIconColor: Color = Color.Unspecified,
        unfocusedTrailingIconColor: Color = Color.Unspecified,
        disabledTrailingIconColor: Color = Color.Unspecified,
        errorTrailingIconColor: Color = Color.Unspecified,
        focusedLabelColor: Color = Color.Unspecified,
        unfocusedLabelColor: Color = Color.Unspecified,
        disabledLabelColor: Color = Color.Unspecified,
        errorLabelColor: Color = Color.Unspecified,
        focusedPlaceholderColor: Color = Color.Unspecified,
        unfocusedPlaceholderColor: Color = Color.Unspecified,
        disabledPlaceholderColor: Color = Color.Unspecified,
        errorPlaceholderColor: Color = Color.Unspecified,
        focusedSupportingTextColor: Color = Color.Unspecified,
        unfocusedSupportingTextColor: Color = Color.Unspecified,
        disabledSupportingTextColor: Color = Color.Unspecified,
        errorSupportingTextColor: Color = Color.Unspecified,
        focusedPrefixColor: Color = Color.Unspecified,
        unfocusedPrefixColor: Color = Color.Unspecified,
        disabledPrefixColor: Color = Color.Unspecified,
        errorPrefixColor: Color = Color.Unspecified,
        focusedSuffixColor: Color = Color.Unspecified,
        unfocusedSuffixColor: Color = Color.Unspecified,
        disabledSuffixColor: Color = Color.Unspecified,
        errorSuffixColor: Color = Color.Unspecified,
    ): TextFieldColors

Creates a TextFieldColors that represents the default input text, container, and content colors (including label, placeholder, icons, etc.) used in a TextField.

Parameters

focusedTextColor the color used for the input text of this text field when focused
unfocusedTextColor the color used for the input text of this text field when not focused
disabledTextColor the color used for the input text of this text field when disabled
errorTextColor the color used for the input text of this text field when in error state
focusedContainerColor the container color for this text field when focused
unfocusedContainerColor the container color for this text field when not focused
disabledContainerColor the container color for this text field when disabled
errorContainerColor the container color for this text field when in error state
cursorColor the cursor color for this text field
errorCursorColor the cursor color for this text field when in error state
selectionColors the colors used when the input text of this text field is selected
focusedIndicatorColor the indicator color for this text field when focused
unfocusedIndicatorColor the indicator color for this text field when not focused
disabledIndicatorColor the indicator color for this text field when disabled
errorIndicatorColor the indicator color for this text field when in error state
focusedLeadingIconColor the leading icon color for this text field when focused
unfocusedLeadingIconColor the leading icon color for this text field when not focused
disabledLeadingIconColor the leading icon color for this text field when disabled
errorLeadingIconColor the leading icon color for this text field when in error state
focusedTrailingIconColor the trailing icon color for this text field when focused
unfocusedTrailingIconColor the trailing icon color for this text field when not focused
disabledTrailingIconColor the trailing icon color for this text field when disabled
errorTrailingIconColor the trailing icon color for this text field when in error state
focusedLabelColor the label color for this text field when focused
unfocusedLabelColor the label color for this text field when not focused
disabledLabelColor the label color for this text field when disabled
errorLabelColor the label color for this text field when in error state
focusedPlaceholderColor the placeholder color for this text field when focused
unfocusedPlaceholderColor the placeholder color for this text field when not focused
disabledPlaceholderColor the placeholder color for this text field when disabled
errorPlaceholderColor the placeholder color for this text field when in error state
focusedSupportingTextColor the supporting text color for this text field when focused
unfocusedSupportingTextColor the supporting text color for this text field when not focused
disabledSupportingTextColor the supporting text color for this text field when disabled
errorSupportingTextColor the supporting text color for this text field when in error state
focusedPrefixColor the prefix color for this text field when focused
unfocusedPrefixColor the prefix color for this text field when not focused
disabledPrefixColor the prefix color for this text field when disabled
errorPrefixColor the prefix color for this text field when in error state
focusedSuffixColor the suffix color for this text field when focused
unfocusedSuffixColor the suffix color for this text field when not focused
disabledSuffixColor the suffix color for this text field when disabled
errorSuffixColor the suffix color for this text field when in error state

ContainerBox

@ExperimentalMaterial3Api
    @Composable
    fun ContainerBox(
        enabled: Boolean,
        isError: Boolean,
        interactionSource: InteractionSource,
        colors: TextFieldColors,
        shape: Shape = TextFieldDefaults.shape,
    ) =
        Container(
            enabled = enabled,
            isError = isError,
            interactionSource = interactionSource,
            modifier = Modifier,
            colors = colors,
            shape = shape,
            focusedIndicatorLineThickness = FocusedIndicatorThickness,
            unfocusedIndicatorLineThickness = UnfocusedIndicatorThickness,
        )

textFieldWithLabelPadding

fun textFieldWithLabelPadding(
        start: Dp = TextFieldPadding,
        end: Dp = TextFieldPadding,
        top: Dp = TextFieldWithLabelVerticalPadding,
        bottom: Dp = TextFieldWithLabelVerticalPadding,
    ): PaddingValues

textFieldWithoutLabelPadding

fun textFieldWithoutLabelPadding(
        start: Dp = TextFieldPadding,
        top: Dp = TextFieldPadding,
        end: Dp = TextFieldPadding,
        bottom: Dp = TextFieldPadding,
    ): PaddingValues

outlinedTextFieldPadding

fun outlinedTextFieldPadding(
        start: Dp = TextFieldPadding,
        top: Dp = TextFieldPadding,
        end: Dp = TextFieldPadding,
        bottom: Dp = TextFieldPadding,
    ): PaddingValues