UX4G Logo
Components

OTP Input

Auto-advancing 4/6-digit verification code input boxes with in-built countdown timer, auto-resend state machine, attempt counters, and locked states

The Ux4gOtpInput is a high-accessibility citizen identity verification component designed for entering one-time passwords (OTP). It features individual digit boxes, auto-focus transitions, animated blinking cursor, paste handling, built-in countdown timers, attempt counters, and status states (Default, Success, Error, Warning, Locked).

Import from com.ux4g.designsystemv1.components.inputfield.Ux4gOtpInput.


Interactive Previews

1. Default OTP Input (Standalone Boxes)

Clean 6-digit verification code boxes without outer label for simple embedded or modal flows.

Ux4gOtpInput (Default Standalone)Jetpack Compose
UX4G Standalone OTP Boxes Preview

2. In-Progress with Focused Cursor & Resend Timer

Standard OTP input with header label, active box focus cursor, and automatic countdown timer.

Ux4gOtpInput (In-Progress with Timer)Jetpack Compose
UX4G OTP Input In-Progress State Preview

3. Verification Successful (Green State)

Valid OTP input showing success green indicators, filled digits, and checkmark confirmation.

Ux4gOtpInput (Verification Successful)Jetpack Compose
UX4G OTP Input Success State Preview

4. Attempt Counter with Error Border & Timer (Red State)

Error state displaying validation warning outline, attempt count badge, and resend action.

Ux4gOtpInput (Error with Attempt Counter)Jetpack Compose
UX4G OTP Input Error State Preview

5. Locked State with Lock Icon (Disabled State)

Disabled OTP input with locked state indicator preventing user interaction when max attempts are exceeded.

Ux4gOtpInput (Locked State)Jetpack Compose
UX4G OTP Input Locked State Preview

Kotlin Usage

Compose Example
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.ux4g.designsystemv1.components.inputfield.Ux4gOtpInput
import com.ux4g.designsystemv1.components.inputfield.Ux4gOtpInputStatus
import com.ux4g.designsystemv1.components.inputfield.Ux4gOtpCaptionVariant

@Composable
fun OtpVerificationScreen() {
    var otp by remember { mutableStateOf("") }
    var status by remember { mutableStateOf(Ux4gOtpInputStatus.Default) }
    var attemptCount by remember { mutableStateOf(1) }

    Column(
        modifier = Modifier
            .fillMaxWidth()
            .padding(16.dp),
        verticalArrangement = Arrangement.spacedBy(16.dp)
    ) {
        Ux4gOtpInput(
            value = otp,
            onValueChange = { newOtp ->
                otp = newOtp
                if (newOtp.length == 6) {
                    // Verify OTP via API
                    if (newOtp == "123456") {
                        status = Ux4gOtpInputStatus.Success
                    } else {
                        status = Ux4gOtpInputStatus.Error
                        attemptCount++
                    }
                }
            },
            label = "Enter 6-Digit Verification Code",
            length = 6,
            status = status,
            captionVariant = when (status) {
                Ux4gOtpInputStatus.Success -> Ux4gOtpCaptionVariant.Success
                Ux4gOtpInputStatus.Error -> Ux4gOtpCaptionVariant.AttemptWithTimer
                Ux4gOtpInputStatus.Locked -> Ux4gOtpCaptionVariant.Locked
                else -> Ux4gOtpCaptionVariant.ResendTimer
            },
            captionLeadingText = if (status == Ux4gOtpInputStatus.Error) "Attempt $attemptCount of 3" else null,
            autoCountdownSeconds = 30,
            onCaptionTrailingTap = {
                // Resend OTP API Trigger
            },
            onComplete = { fullOtp ->
                // Complete callback
            }
        )
    }
}

Parameters

Ux4gOtpInput Props

PropTypeDescriptionDefault
value *StringCurrent OTP string entered by the citizen.—
onValueChange *(String) -> UnitCallback invoked on each digit input or deletion.—
labelString?Header title label displayed above the digit boxes.null
lengthIntNumber of OTP digit boxes (typically 4 or 6).6
statusUx4gOtpInputStatusBorder and surface validation status: Default, Focused, Success, Warning, Error, Locked.Ux4gOtpInputStatus.Default
captionVariantUx4gOtpCaptionVariantPre-built caption footer variant: ResendTimer, ResendAction, AttemptWithTimer, Locked, Success, Warning, Plain.Ux4gOtpCaptionVariant.Plain
captionTextString?Custom plain caption text string (for .Plain or .Success variants).null
captionLeadingTextString?Left-aligned caption text (e.g. "Attempt 2 of 3" or "Locked for 28:43").null
captionTrailingTextString?Right-aligned caption text (e.g. "Resend in 00:17" or "Resend OTP").null
autoCountdownSecondsInt?Built-in auto-decrementing timer seconds (e.g. 17 -> 00:17).null
onCaptionTrailingTap(() -> Unit)?Tap action trigger for the trailing resend button or link.null
onComplete((String) -> Unit)?Callback triggered automatically when all digits are filled.null
obscureBooleanObscures entered digits with bullets (•) for password/PIN modes.false
enabledBooleanInteractive state. Disables digit editing and touch events when false.true
modifierModifierCompose layout modifier applied to the outer container.Modifier

On this page