TextField

@Composable
fun TextField(state: TextFieldState, modifier: Modifier = Modifier, singleLine: Boolean = false, maxLines: Int = Int.MAX_VALUE, minLines: Int = 1, placeholder: String = "", color: Color = Color.Unspecified, placeholderColor: Color = Color.Unspecified, textStyle: TextStyle = TextStyle.Unspecified, onSubmit: (text: String) -> Unit? = null)

An editable text field.

The field is focusable. While focused, key presses and pastes edit state, and the terminal's cursor is placed at its cursor so that input methods show their composition there. Use focusRequester to focus it when there are several focusable nodes. Text is wrapped to the width of the field, at spaces where possible. The field is at least minLines and at most maxLines lines high, and scrolls to keep the cursor visible.

When onSubmit is set, Enter calls it with the text. Otherwise, and with Shift+Enter or Alt+Enter, it inserts a line break unless this is singleLine. Pasted line breaks become spaces in a singleLine field.

The usual editing keys work, along with these:

  • Alt or Ctrl with ← and →, or Alt+B and Alt+F, move by words. Alt+Backspace and Alt+D delete them.

  • ↑ and ↓ move between rows. On the first and last row, they are left for other handlers, for example to recall earlier input.

  • Shift with the keys which move the cursor selects text, as does dragging the mouse, which copies the selection to the clipboard once released. Typing replaces the selection.

  • Ctrl+A and Ctrl+E move to the start and end of the line. Ctrl+U and Ctrl+K delete to them, and Ctrl+W deletes the previous word, so that Ctrl+Y inserts it again, like in a shell.

  • Ctrl+_ (or Ctrl+/) undoes the last edit, and Ctrl+Shift+Z redoes it where the terminal tells them apart from Ctrl+Z.