# BasicSecureTextField

Common/AllAndroid/JVM

## Functions summary

|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/BasicSecureTextField.composable#BasicSecureTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.input.KeyboardActionHandler,kotlin.Function2,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Brush,androidx.compose.foundation.text.input.TextFieldDecorator,androidx.compose.foundation.text.input.TextObfuscationMode,kotlin.Char,androidx.compose.foundation.ScrollState)( state: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState, modifier: https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier, enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, readOnly: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, inputTransformation: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation?, textStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextStyle, keyboardOptions: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/KeyboardOptions, onKeyboardAction: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/KeyboardActionHandler?, onTextLayout: (https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density.(getResult: () -> https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextLayoutResult?) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)?, interactionSource: https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource?, cursorBrush: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Brush, decorator: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldDecorator?, textObfuscationMode: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextObfuscationMode, textObfuscationCharacter: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char/index.html, scrollState: https://developer.android.com/reference/kotlin/androidx/compose/foundation/ScrollState )` BasicSecureTextField is specifically designed for password entry fields and is a preconfigured alternative to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/BasicTextField.composable#BasicTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.input.KeyboardActionHandler,androidx.compose.foundation.text.input.TextFieldLineLimits,kotlin.Function2,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Brush,androidx.compose.foundation.text.input.OutputTransformation,androidx.compose.foundation.text.input.TextFieldDecorator,androidx.compose.foundation.ScrollState)`. | Cmn |

## Functions

### BasicSecureTextField

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/BasicSecureTextField.kt+function:BasicSecureTextField)

```
@Composable
fun BasicSecureTextField(
    state: TextFieldState,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    readOnly: Boolean = false,
    inputTransformation: InputTransformation? = null,
    textStyle: TextStyle = TextStyle.Default,
    keyboardOptions: KeyboardOptions = KeyboardOptions.SecureTextField,
    onKeyboardAction: KeyboardActionHandler? = null,
    onTextLayout: (Density.(getResult: () -> TextLayoutResult?) -> Unit)? = null,
    interactionSource: MutableInteractionSource? = null,
    cursorBrush: Brush = SolidColor(Color.Black),
    decorator: TextFieldDecorator? = null,
    textObfuscationMode: TextObfuscationMode = TextObfuscationMode.System,
    textObfuscationCharacter: Char = DefaultObfuscationCharacter,
    scrollState: ScrollState = rememberScrollState()
): Unit
```

BasicSecureTextField is specifically designed for password entry fields and is a preconfigured alternative to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/BasicTextField.composable#BasicTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.input.KeyboardActionHandler,androidx.compose.foundation.text.input.TextFieldLineLimits,kotlin.Function2,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Brush,androidx.compose.foundation.text.input.OutputTransformation,androidx.compose.foundation.text.input.TextFieldDecorator,androidx.compose.foundation.ScrollState)`. It only supports a single line of content and comes with default settings for `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/KeyboardOptions`, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation`, and that are appropriate for entering secure content. Additionally, some context menu actions like cut, copy, and drag are disabled for added security.

```kotlin
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicSecureTextField
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.text.input.InputTransformation
import androidx.compose.foundation.text.input.byValue
import androidx.compose.foundation.text.input.maxLengthTrim
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp

val pinState = rememberTextFieldState()
val pinLength = 4

BasicSecureTextField(
    state = pinState,
    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword),
    inputTransformation =
        InputTransformation.byValue { _, proposed -> proposed.filter { it.isDigit() } }
            .maxLengthTrim(pinLength),
    decorator = { innerTextField ->
        Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
            repeat(pinLength) { index ->
                val char = pinState.text.getOrNull(index)
                Box(
                    modifier =
                        Modifier.size(48.dp)
                            .border(
                                1.dp,
                                if (pinState.text.length == index) Color.Blue else Color.Gray,
                                RoundedCornerShape(8.dp),
                            ),
                    contentAlignment = Alignment.Center,
                ) {
                    if (char != null) {
                        Text("●")
                    }
                }
            }
        }
    },
)
```

| Parameters |
|---|---|
| `state: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState` object that holds the internal state of a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/BasicSecureTextField.composable#BasicSecureTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.input.KeyboardActionHandler,kotlin.Function2,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Brush,androidx.compose.foundation.text.input.TextFieldDecorator,androidx.compose.foundation.text.input.TextObfuscationMode,kotlin.Char,androidx.compose.foundation.ScrollState)`. |
| `modifier: https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier = Modifier` | optional `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` for this text field. |
| `enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = true` | controls the enabled state of the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/BasicSecureTextField.composable#BasicSecureTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.input.KeyboardActionHandler,kotlin.Function2,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Brush,androidx.compose.foundation.text.input.TextFieldDecorator,androidx.compose.foundation.text.input.TextObfuscationMode,kotlin.Char,androidx.compose.foundation.ScrollState)`. When `false`, the text field will be neither editable nor focusable, the input of the text field will not be selectable. |
| `readOnly: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | controls the editable state of the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/BasicSecureTextField.composable#BasicSecureTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.input.KeyboardActionHandler,kotlin.Function2,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Brush,androidx.compose.foundation.text.input.TextFieldDecorator,androidx.compose.foundation.text.input.TextObfuscationMode,kotlin.Char,androidx.compose.foundation.ScrollState)`. When `true`, the text field can not be modified, however, a user can focus on it. Read-only text fields are usually used to display pre-filled forms that a user can not edit. |
| `inputTransformation: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation? = null` | Optional `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` that will be used to transform changes to the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState` made by the user. The transformation will be applied to changes made by hardware and software keyboard events, pasting or dropping text, accessibility services, and tests. The transformation will *not* be applied when changing the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/package-summary#BasicSecureTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.input.KeyboardActionHandler,kotlin.Function2,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Brush,androidx.compose.foundation.text.input.TextFieldDecorator,androidx.compose.foundation.text.input.TextObfuscationMode,kotlin.Char,androidx.compose.foundation.ScrollState)` programmatically, or when the transformation is changed. If the transformation is changed on an existing text field, it will be applied to the next user edit. The transformation will not immediately affect the current `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/package-summary#BasicSecureTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.input.KeyboardActionHandler,kotlin.Function2,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Brush,androidx.compose.foundation.text.input.TextFieldDecorator,androidx.compose.foundation.text.input.TextObfuscationMode,kotlin.Char,androidx.compose.foundation.ScrollState)`. |
| `textStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextStyle = TextStyle.Default` | Style configuration for text content that's displayed in the editor. |
| `keyboardOptions: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/KeyboardOptions = KeyboardOptions.SecureTextField` | Software keyboard options that contain configurations such as `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/KeyboardType` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/ImeAction`. This composable by default configures `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/KeyboardOptions` for a secure text field by disabling auto correct and setting `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/KeyboardType` to `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/KeyboardType#Password()`. If using `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextObfuscationMode#Visible()`, consider passing `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/KeyboardType#PasswordVisible()` instead to indicate to the IME that the input is visible. |
| `onKeyboardAction: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/KeyboardActionHandler? = null` | Called when the user presses the action button in the input method editor (IME), or by pressing the enter key on a hardware keyboard. By default this parameter is null, and would execute the default behavior for a received IME Action e.g., `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/ImeAction#Done()` would close the keyboard, `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/ImeAction#Next()` would switch the focus to the next focusable item on the screen. |
| `onTextLayout: (https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density.(getResult: () -> https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextLayoutResult?) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? = null` | Callback that is executed when the text layout becomes queryable. The callback receives a function that returns a `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextLayoutResult` if the layout can be calculated, or null if it cannot. The function reads the layout result from a snapshot state object, and will invalidate its caller when the layout result changes. A `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextLayoutResult` object contains paragraph information, size of the text, baselines and other details. The callback can be used to add additional decoration or functionality to the text. For example, to draw a cursor or selection around the text. `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density` scope is the one that was used while creating the given text layout. |
| `interactionSource: https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource? = null` | the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource` representing the stream of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/Interaction`s for this TextField. You can create and pass in your own remembered `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource` if you want to observe `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/Interaction`s and customize the appearance / behavior of this TextField for different `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/Interaction`s. |
| `cursorBrush: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Brush = SolidColor(Color.Black)` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Brush` to paint cursor with. If `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/SolidColor` with `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color#Unspecified()` provided, there will be no cursor drawn. |
| `decorator: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldDecorator? = null` | Allows to add decorations around text field, such as icon, placeholder, helper messages or similar, and automatically increase the hit target area of the text field. |
| `textObfuscationMode: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextObfuscationMode = TextObfuscationMode.System` | Determines the method used to obscure the input text. |
| `textObfuscationCharacter: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char/index.html = DefaultObfuscationCharacter` | Which character to use while obfuscating the text. It doesn't have an effect when `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/package-summary#BasicSecureTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.input.KeyboardActionHandler,kotlin.Function2,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Brush,androidx.compose.foundation.text.input.TextFieldDecorator,androidx.compose.foundation.text.input.TextObfuscationMode,kotlin.Char,androidx.compose.foundation.ScrollState)` is set to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextObfuscationMode#Visible()`. |
| `scrollState: https://developer.android.com/reference/kotlin/androidx/compose/foundation/ScrollState = rememberScrollState()` | The scroll state of the text field. Since `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/BasicSecureTextField.composable#BasicSecureTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.input.KeyboardActionHandler,kotlin.Function2,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Brush,androidx.compose.foundation.text.input.TextFieldDecorator,androidx.compose.foundation.text.input.TextObfuscationMode,kotlin.Char,androidx.compose.foundation.ScrollState)` is always single line, this scroll state always controls a horizontal scroll. |