androidx.compose.foundation.text.input
TextFieldState
Class · from org.jetbrains.compose.foundation:foundation:1.12.2
No hand-written docs yet.
The editable text state of a text field, including both the text itself and position of the cursor or selection.
class TextFieldState
Used by
Parameters that take a TextFieldState.
BasicSecureTextField(state)BasicTextField(state)OutlinedSecureTextField(state)OutlinedTextField(state)SearchBarDefaults.InputField(textFieldState, state)SecureTextField(state)TextField(state)OutlinedTextFieldDefaults.decorator(state)TextFieldDefaults.decorator(state)
Properties
text
val text: CharSequence
The current text content. This value will automatically update when the user enters text or otherwise changes the text field contents. To change it programmatically, call edit.
selection
val selection: TextRange
The current selection range. If the selection is collapsed, it represents cursor location. This value will automatically update when the user enters text or otherwise changes the text field selection range. To change it programmatically, call edit.
composition
val composition: TextRange?
The current composing range dictated by the IME. If null, there is no composing region.
textStylesSince 1.12
val textStyles: TextFieldTextStyles
Provides access to the styles applied to the text within this TextFieldState.
undoStateExperimental
val undoState: UndoState
Undo history controller for this TextFieldState.
Functions
edit
fun edit(block: TextFieldBuffer.() -> Unit)
Runs block with a mutable version of the current state. The block can make changes to the text and cursor/selection. See the documentation on TextFieldBuffer for a more detailed description of the available operations.
Nested types
Saver
Library docs
The editable text state of a text field, including both the text itself and position of the
cursor or selection.
To change the text field contents programmatically, call edit, setTextAndSelectAll,
setTextAndPlaceCursorAtEnd, or clearText. Individual parts of the state like text,
selection, or composition can be read from any snapshot restart scope like Composable
functions. To observe these members from outside a restart scope, use snapshotFlow { textFieldState.text } or snapshotFlow { textFieldState.selection }.
When instantiating this class from a composable, use rememberTextFieldState to automatically
save and restore the field state. For more advanced use cases, pass TextFieldState.Saver to
rememberSaveable.