by @alexstyl
✉️ Leave your feedback

← Back to Foundation text

CoreTextField

Component
in
Foundation text
. Since 0.1.0-dev15

Overview

Examples

Community Notes

Base composable that enables users to edit text via hardware or software keyboard.

This composable provides basic text editing functionality, however does not include any decorations such as borders, hints/placeholder.

Whenever the user edits the text, onValueChange is called with the most up to date state represented by TextFieldValue. TextFieldValue contains the text entered by user, as well as selection, cursor and text composition information. Please check TextFieldValue for the description of its contents.

It is crucial that the value provided in the onValueChange is fed back into CoreTextField in order to have the final state of the text being displayed.

Overloads

CoreTextField

@Composable
@OptIn(
    ExperimentalFocus::class,
    ExperimentalTextApi::class,
    MouseTemporaryApi::class
)
@InternalTextApi
fun CoreTextField(
    value: TextFieldValue,
    modifier: Modifier = Modifier,
    onValueChange: (TextFieldValue) -> Unit,
    textStyle: TextStyle = TextStyle.Default,
    onImeActionPerformed: (ImeAction) -> Unit = {},
    visualTransformation: VisualTransformation = VisualTransformation.None,
    onTextLayout: (TextLayoutResult) -> Unit = {},
    onTextInputStarted: (SoftwareKeyboardController) -> Unit = {},
    cursorColor: Color = Color.Unspecified,
    softWrap: Boolean = true,
    maxLines: Int = Int.MAX_VALUE,
    imeOptions: ImeOptions = ImeOptions.Default
)

Parameters

NameDescription
valueThe androidx.compose.ui.text.input.TextFieldValue to be shown in the CoreTextField.
onValueChangeCalled when the input service updates the values in TextFieldValue.
modifieroptional Modifier for this text field.
textStyleStyle configuration that applies at character level such as color, font etc.
onImeActionPerformedCalled when the input service requested an IME action. When the input service emitted an IME action, this callback is called with the emitted IME action. Note that this IME action may be different from what you specified in imeAction.
visualTransformationThe visual transformation filter for changing the visual representation of the input. By default no visual transformation is applied.
onTextLayoutCallback that is executed when a new text layout is calculated.
onTextInputStartedCallback that is executed when the initialization has done for communicating with platform text input service, e.g. software keyboard on Android. Called with SoftwareKeyboardController instance which can be used for requesting input show/hide software keyboard.
cursorColorColor of the cursor. If Color.Unspecified, there will be no cursor drawn
softWrapWhether the text should break at soft line breaks. If false, the glyphs in the text will be positioned as if there was unlimited horizontal space.
maxLinesthe maximum height in terms of maximum number of visible lines. Should be equal or greater than 1
Previous ComponentCoreText