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.
2. In-Progress with Focused Cursor & Resend Timer
Standard OTP input with header label, active box focus cursor, and automatic countdown timer.
3. Verification Successful (Green State)
Valid OTP input showing success green indicators, filled digits, and checkmark confirmation.
4. Attempt Counter with Error Border & Timer (Red State)
Error state displaying validation warning outline, attempt count badge, and resend action.
5. Locked State with Lock Icon (Disabled State)
Disabled OTP input with locked state indicator preventing user interaction when max attempts are exceeded.
Kotlin Usage
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
| Prop | Type | Description | Default |
|---|---|---|---|
value * | String | Current OTP string entered by the citizen. | — |
onValueChange * | (String) -> Unit | Callback invoked on each digit input or deletion. | — |
label | String? | Header title label displayed above the digit boxes. | null |
length | Int | Number of OTP digit boxes (typically 4 or 6). | 6 |
status | Ux4gOtpInputStatus | Border and surface validation status: Default, Focused, Success, Warning, Error, Locked. | Ux4gOtpInputStatus.Default |
captionVariant | Ux4gOtpCaptionVariant | Pre-built caption footer variant: ResendTimer, ResendAction, AttemptWithTimer, Locked, Success, Warning, Plain. | Ux4gOtpCaptionVariant.Plain |
captionText | String? | Custom plain caption text string (for .Plain or .Success variants). | null |
captionLeadingText | String? | Left-aligned caption text (e.g. "Attempt 2 of 3" or "Locked for 28:43"). | null |
captionTrailingText | String? | Right-aligned caption text (e.g. "Resend in 00:17" or "Resend OTP"). | null |
autoCountdownSeconds | Int? | 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 |
obscure | Boolean | Obscures entered digits with bullets (•) for password/PIN modes. | false |
enabled | Boolean | Interactive state. Disables digit editing and touch events when false. | true |
modifier | Modifier | Compose layout modifier applied to the outer container. | Modifier |