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-inputType 482913 to verify, or any other code to see the error.
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.
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add otp-inputuse 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
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.
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.
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.
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.
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).
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
| Prop | Type | Default | Description |
|---|---|---|---|
length | usize | 6 | Number of boxes (4–8). |
separator | Option<usize> | Default::default() | A dash after this many boxes (`0` = the middle). |
numeric | bool | true | Digits only (else letters too, in capitals). |
value | String | Default::default() | Starting code. |
status | String | "idle" | `idle` · `verifying` · `error` · `success`. |
error_message | String | "That code didn't work. Try again." | Shown after an error. |
clear_on_error | bool | true | Clear the boxes after the shake. |
success_label | String | "Verified" | Text in the success pill. |
resend_in | Option<u32> | Some(30) | Seconds until resend (`None` hides resend). |
align | String | "start" | `start` · `center`. |
disabled | bool | Default::default() | Disabled. |
auto_focus | bool | Default::default() | Focus on mount. |
label | String | "Verification code" | Accessible name (the number of digits is added). |
masked | bool | Default::default() | Oxyn plus: dots instead of characters. |
attempts | Option<u32> | Default::default() | Oxyn plus: tries left. |
expect | Option<String> | Default::default() | Oxyn plus (demos): verify locally against this code. |
on_change | EventHandler<String> | — | Every change. |
on_complete | EventHandler<String> | — | The last box was filled. |
on_resend | EventHandler<()> | — | Resend pressed. |
Read from the Rust signature and doc comments.
Keyboard interactions
| Key | Action |
|---|---|
| 0–9 | Fill 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 |
| HomeorEnd | First box / the next empty one |
| ⌘orCtrlV | Paste 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
| Transition | Duration | Easing | Reduced motion |
|---|---|---|---|
| Ring glide | 214 ms spring.snap | spring | jump |
| Digit in | 140 ms, stagger 40 ms on paste | ease.out | instant |
| Verifying sheen | 1.1 s loop | linear | static muted |
| Error shake | 420 ms, 6 → 0 px | damped sine | none |
| Clear after error | 420 ms | — | 420 ms |
| Success morph | 360 ms + 260 ms check | ease.out | crossfade |
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
OtpInputfromoxyn_dioxusand includePRIMITIVES_CSSplus the token stylesheet once. - A GPUI version exists:
OtpElinoxyn_gpui. - Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.