Skip to content
Back

OTP Input

The verification-code field: a gliding focus ring, paste and SMS autofill, a calm shake on errors and a morph into Verified.

oxyn add otp-input
MCP
Didn't get a code? Resend in 0:30

Type 482913 to verify, or any other code to see the error.

Dioxus
rsx! {
    OtpInput {
        length: 6,
        numeric: true,
        separator: Some(0),
        status: status(),
        attempts: None,
        resend_in: Some(30),
        on_complete: move |code: String| verify(code),
        on_resend: move |_| send_code(),
    }
}

Rendered from Rust at build time · goes live when visible

When to use

  • The verification code after sign-in, a new device, or an agent asking to confirm a sensitive action.
  • The user types or pastes six digits and wants to know at once whether it worked.

When not to use

  • One input for every form: use Text Field instead.
  • A password input whose reveal button slashes the eye with a drawn line, with a Caps Lock warning and a reveal that hides itself again: use Password field instead.
  • An agent asks before it acts: use Approval Card instead.

Installation

OTP Input is free and MIT. The oxyn CLI copies its code, and the components it needs, into src/oxyn/ of your Dioxus or GPUI project, so it is yours to change.

Terminal
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add otp-input
Rust
use crate::oxyn::{OtpInput, PRIMITIVES_CSS};

Rather depend on the crate? cargo add oxyn-dioxus oxyn-core --git https://github.com/ismailqureshi72/Oxyn, then use oxyn_dioxus::{OtpInput, PRIMITIVES_CSS};

Usage

Dioxus · rust
rsx! {
    OtpInput {
        length: 6,
        numeric: true,
        separator: Some(0),
        status: status(),
        attempts: None,
        resend_in: Some(30),
        on_complete: move |code: String| verify(code),
        on_resend: move |_| send_code(),
    }
}

Examples

Idle

Six digits with a dash in the middle.

Didn't get a code? Resend in 0:30

Type 482913 to verify, or any other code to see the error.

Code
rsx! {
    OtpInput {
        length: 6,
        numeric: true,
        separator: Some(0),
        status: status(),
        attempts: None,
        resend_in: Some(30),
        on_complete: move |code: String| verify(code),
        on_resend: move |_| send_code(),
    }
}

Verifying

Light passes over the locked boxes.

Didn't get a code? Resend in 0:30
Verifying code

Type 482913 to verify, or any other code to see the error.

Code
rsx! {
    OtpInput {
        length: 6,
        numeric: true,
        separator: Some(0),
        status: status(),
        attempts: None,
        resend_in: Some(30),
        on_complete: move |code: String| verify(code),
        on_resend: move |_| send_code(),
    }
}

Error

Shake, red edges, then the code clears.

That code didn't work. Try again. 3 tries left.
That code didn't work. Try again.

Type 482913 to verify, or any other code to see the error.

Code
rsx! {
    OtpInput {
        length: 6,
        numeric: true,
        separator: Some(0),
        status: status(),
        attempts: Some(3),
        resend_in: Some(30),
        on_complete: move |code: String| verify(code),
        on_resend: move |_| send_code(),
    }
}

Success

Boxes merge into the Verified pill.

Verified
Verified

Type 482913 to verify, or any other code to see the error.

Code
rsx! {
    OtpInput {
        length: 6,
        numeric: true,
        separator: Some(0),
        status: status(),
        attempts: None,
        resend_in: Some(30),
        on_complete: move |code: String| verify(code),
        on_resend: move |_| send_code(),
    }
}

Alphanumeric

Five letters or digits, masked (Oxyn plus).

Didn't get a code? Resend in 0:30

Type K7Q2M to verify, or any other code to see the error.

Code
rsx! {
    OtpInput {
        length: 5,
        numeric: false,
        separator: None,
        status: status(),
        masked: true,
        attempts: None,
        resend_in: Some(30),
        on_complete: move |code: String| verify(code),
        on_resend: move |_| send_code(),
    }
}

API reference

OtpInput

PropTypeDefaultDescription
lengthusize6Number of boxes (4–8).
separatorOption<usize>Default::default()A dash after this many boxes (`0` = the middle).
numericbooltrueDigits only (else letters too, in capitals).
valueStringDefault::default()Starting code.
statusString"idle"`idle` · `verifying` · `error` · `success`.
error_messageString"That code didn't work. Try again."Shown after an error.
clear_on_errorbooltrueClear the boxes after the shake.
success_labelString"Verified"Text in the success pill.
resend_inOption<u32>Some(30)Seconds until resend (`None` hides resend).
alignString"start"`start` · `center`.
disabledboolDefault::default()Disabled.
auto_focusboolDefault::default()Focus on mount.
labelString"Verification code"Accessible name (the number of digits is added).
maskedboolDefault::default()Oxyn plus: dots instead of characters.
attemptsOption<u32>Default::default()Oxyn plus: tries left.
expectOption<String>Default::default()Oxyn plus (demos): verify locally against this code.
on_changeEventHandler<String>—Every change.
on_completeEventHandler<String>—The last box was filled.
on_resendEventHandler<()>—Resend pressed.

Read from the Rust signature and doc comments.

Keyboard interactions

KeyAction
0–9Fill the active box and move on; typing on a filled box replaces it
⌫Clear the box and go back one
←or→Move between the filled boxes and the next empty one
HomeorEndFirst box / the next empty one
⌘orCtrlVPaste a whole code; spaces and dashes are ignored

Accessibility

  • One real input carries the whole code: “Verification code, 6 digits”.
  • autocomplete=one-time-code and inputmode=numeric for SMS autofill and the number pad.
  • Errors set aria-invalid and point to the message; verifying, errors, success and resend are announced politely.
From the spec

One real input holds the whole code (autocomplete=one-time-code, inputmode=numeric), so SMS autofill, paste and screen readers work; the boxes are aria-hidden. The name includes the length. Verifying, errors (with tries left), success and resend are announced in a polite region. Colour is never the only signal: errors also shake and show text.

Motion & interaction

One focus ring glides from box to box rather than each box drawing its own. Pasted digits land 40 ms apart. The error shake decays over three swings; digits fade then clear. Success: boxes slide together and the frame morphs into a pill; the check draws.

Timing
TransitionDurationEasingReduced motion
Ring glide214 ms spring.snapspringjump
Digit in140 ms, stagger 40 ms on pasteease.outinstant
Verifying sheen1.1 s looplinearstatic muted
Error shake420 ms, 6 → 0 pxdamped sinenone
Clear after error420 ms—420 ms
Success morph360 ms + 260 ms checkease.outcrossfade

Responsive behaviour

  • The boxes shrink to their container: six with a separator fit a 320 px phone.
  • The input uses 16 px text so iOS doesn't zoom.
Edge cases (spec)

Paste with spaces or dashes is cleaned. A paste longer than the field fills from the first box. Clicking a box past the next empty one focuses the next empty one. Narrow phones: boxes shrink to their container (six + separator fit 320 px). 16 px input text so iOS doesn't zoom. Slow verify: the sheen continues; nothing can be typed.

Notes for AI

  • Import OtpInput from oxyn_dioxus and include PRIMITIVES_CSS plus the token stylesheet once.
  • A GPUI version exists: OtpEl in oxyn_gpui.
  • Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.

Guides

Oxyn · 74 free components · 264 Pro components · 96 screens · 20 blocks · Dioxus and GPUI