---
title: "KeyboardActions"
description: "Configures custom actions to run when the action button on the software keyboard (such as the \"Done\", \"Search\", or \"Next\" button in the bottom corner of the keyboard) is clicked."
type: "class"
---
## API Reference

> Source set: Common

```kotlin
public class KeyboardActions(
    /**
     * This is run when the user triggers the [Done][ImeAction.Done] action. A null value indicates
     * that the default implementation if any, should be executed.
     */
    public val onDone: (KeyboardActionScope.() -> Unit)? = null,

    /**
     * This is run when the user triggers the [Go][ImeAction.Go] action. A null value indicates that
     * the default implementation if any, should be executed.
     */
    public val onGo: (KeyboardActionScope.() -> Unit)? = null,

    /**
     * This is run when the user triggers the [Next][ImeAction.Next] action. A null value indicates
     * that the default implementation should be executed. The default implementation moves focus to
     * the next item in the focus traversal order.
     *
     * See [Modifier.focusProperties()][androidx.compose.ui.focus.focusProperties] for more details
     * on how to specify a custom focus order if needed.
     */
    public val onNext: (KeyboardActionScope.() -> Unit)? = null,

    /**
     * This is run when the user triggers the [Previous][ImeAction.Previous] action. A null value
     * indicates that the default implementation should be executed. The default implementation
     * moves focus to the previous item in the focus traversal order.
     *
     * See [Modifier.focusProperties()][androidx.compose.ui.focus.focusProperties] for more details
     * on how to specify a custom focus order if needed.
     */
    public val onPrevious: (KeyboardActionScope.() -> Unit)? = null,

    /**
     * This is run when the user triggers the [Search][ImeAction.Search] action. A null value
     * indicates that the default implementation if any, should be executed.
     */
    public val onSearch: (KeyboardActionScope.() -> Unit)? = null,

    /**
     * This is run when the user triggers the [Send][ImeAction.Send] action. A null value indicates
     * that the default implementation if any, should be executed.
     */
    public val onSend: (KeyboardActionScope.() -> Unit)? = null,
)
```

Configures custom actions to run when the action button on the software keyboard (such as the
"Done", "Search", or "Next" button in the bottom corner of the keyboard) is clicked.

Setting these actions overrides default behavior, allowing you to implement custom focus routing
(e.g., moving focus to a specific field on Next) or trigger custom logic (e.g., hiding the
keyboard or submitting data on Done).

Use `KeyboardActionScope.defaultKeyboardAction` to run the default action for the triggered
`ImeAction`.

## Functions

### equals

> Source set: Common

```kotlin
override fun equals(other: Any?): Boolean
```

### hashCode

> Source set: Common

```kotlin
override fun hashCode(): Int
```

## Members

### Companion

> Source set: Common

```kotlin
public companion object
```

## Properties

### Default

> Source set: Common

```kotlin
@Stable public val Default: KeyboardActions = KeyboardActions()
```

Use this default value if you don't want to specify any action but want to use the
default action implementations.

## Code Examples

### RegistrationFormSample

```kotlin
/**
 * A complete profile registration screen sample. Shows how to handle standard name entries, login
 * emails, physical mailing address lines, secure password visibility eye-icon togglers, and natural
 * language biography summaries.
 */
@Sampled
@Composable
fun RegistrationFormSample() {
    val nameState = rememberTextFieldState()
    val emailState = rememberTextFieldState()
    val passwordState = rememberTextFieldState()
    var isPasswordVisible by remember { mutableStateOf(false) }
    val urlState = rememberTextFieldState()
    val addressState = rememberTextFieldState()
    val biographyState = rememberTextFieldState()

    Column(
        verticalArrangement = Arrangement.spacedBy(12.dp),
        modifier = Modifier.padding(16.dp).fillMaxWidth(),
    ) {
        // 1. PersonName Input (Auto-Capitalizes Words)
        OutlinedTextField(
            state = nameState,
            label = { Text("Full Name") },
            keyboardOptions =
                KeyboardOptions(
                    keyboardType = KeyboardType.PersonName,
                    capitalization = KeyboardCapitalization.Words,
                    imeAction = ImeAction.Next, // Soft keyboard automatically moves focus on Next
                ),
            lineLimits = TextFieldLineLimits.SingleLine,
            modifier = Modifier.fillMaxWidth(),
        )

        // 2. Email Input (Restricted layout showing '@' and '.', auto-capitalization disabled)
        OutlinedTextField(
            state = emailState,
            label = { Text("Email") },
            keyboardOptions =
                KeyboardOptions(
                    keyboardType = KeyboardType.Email,
                    capitalization = KeyboardCapitalization.None,
                    imeAction = ImeAction.Next,
                ),
            lineLimits = TextFieldLineLimits.SingleLine,
            modifier = Modifier.fillMaxWidth(),
        )

        // 3. Password Input with Eye-Icon Toggle (masked vs visible password layouts,
        // capitalizations disabled)
        Row(verticalAlignment = Alignment.CenterVertically) {
            OutlinedSecureTextField(
                state = passwordState,
                label = { Text("Password") },
                textObfuscationMode =
                    if (isPasswordVisible) TextObfuscationMode.Visible
                    else TextObfuscationMode.System,
                keyboardOptions =
                    KeyboardOptions(
                        keyboardType =
                            if (isPasswordVisible) KeyboardType.PasswordVisible
                            else KeyboardType.Password,
                        capitalization = KeyboardCapitalization.None,
                        imeAction = ImeAction.Next,
                    ),
                modifier = Modifier.weight(0.7f),
            )
            Spacer(Modifier.width(8.dp))
            TextButton(
                onClick = { isPasswordVisible = !isPasswordVisible },
                modifier = Modifier.weight(0.3f),
            ) {
                Text(if (isPasswordVisible) "Hide" else "Show")
            }
        }

        // 4. Uri Input (Prominent '/' and '.com' keys, auto-capitalization disabled)
        OutlinedTextField(
            state = urlState,
            label = { Text("Homepage URL") },
            keyboardOptions =
                KeyboardOptions(
                    keyboardType = KeyboardType.Uri,
                    capitalization = KeyboardCapitalization.None,
                    imeAction = ImeAction.Next,
                ),
            lineLimits = TextFieldLineLimits.SingleLine,
            modifier = Modifier.fillMaxWidth(),
        )

        // 5. PostalAddress Input (Auto-Capitalizes Words, prompts standard shipping keys)
        OutlinedTextField(
            state = addressState,
            label = { Text("Shipping Address") },
            keyboardOptions =
                KeyboardOptions(
                    keyboardType = KeyboardType.PostalAddress,
                    capitalization = KeyboardCapitalization.Words,
                    imeAction = ImeAction.Next,
                ),
            lineLimits = TextFieldLineLimits.SingleLine,
            modifier = Modifier.fillMaxWidth(),
        )

        // 6. Free-Text Biography Input (Auto-Capitalizes Sentences, multi-line active)
        OutlinedTextField(
            state = biographyState,
            label = { Text("Biography") },
            keyboardOptions =
                KeyboardOptions(
                    keyboardType = KeyboardType.Text,
                    capitalization = KeyboardCapitalization.Sentences,
                    imeAction =
                        ImeAction.Done, // Soft keyboard automatically dismisses keyboard on Done
                ),
            modifier = Modifier.fillMaxWidth(),
        )
    }
}

/**
 * A register cashier checkout panel sample. Shows how to build secure cashier PIN rows, automatic
 * dollar currency amounts input formatters, integer item quantities, customer phone dialers, and
 * capitalized promo voucher entry lines.
 */
```

### BasicLoginFormSample

```kotlin
/**
 * A standard login form with email and password text fields. Auto-capitalization and autocorrect
 * are disabled to make it easier to type credentials. Uses standard default IME actions to
 * automatically move focus on Next and Done.
 */
@Sampled
@Composable
fun BasicLoginFormSample() {
    val emailState = rememberTextFieldState()
    val passwordState = rememberTextFieldState()

    Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
        OutlinedTextField(
            state = emailState,
            label = { Text("Email Address") },
            keyboardOptions =
                KeyboardOptions(
                    keyboardType = KeyboardType.Email,
                    capitalization = KeyboardCapitalization.None,
                    imeAction =
                        ImeAction
                            .Next, // Soft keyboard automatically shifts focus to password field on
                    // Next
                ),
            lineLimits = TextFieldLineLimits.SingleLine,
            modifier = Modifier.fillMaxWidth(),
        )

        OutlinedSecureTextField(
            state = passwordState,
            label = { Text("Password") },
            keyboardOptions =
                KeyboardOptions(
                    keyboardType = KeyboardType.Password,
                    capitalization = KeyboardCapitalization.None,
                    imeAction =
                        ImeAction.Done, // Soft keyboard automatically dismisses the keyboard on Done
                ),
            modifier = Modifier.fillMaxWidth(),
        )
    }
}

/**
 * A masked 4-digit PIN entry row (like a lockscreen PIN pad). Uses customized cell box borders that
 * mask typed digits with dots.
 *
 * Demonstrates using [BasicSecureTextField] to implement custom cell-by-cell decoration.
 */
```
