Data Entryduskmoonimplemented1 demos
OtpInput
OtpInput captures an OTP or PIN through one native text input and decorative slots.
Import
@duskmoon-dev/components/otp-input5API sections
6documented props
3behavior scenarios
Usage
When to use
- Use it inside forms, filters, settings, and any workflow that captures user input.
- Prefer controlled props when the value must stay synchronized with application state.
Implementation notes
StylesheetImport @duskmoon-dev/components/styles.css once in the app or docs shell.
StateStart with default props for static examples, then switch to controlled props when state must be shared.
ThemeThe preview inherits the active DuskMoon data-theme value from the docs layout.
Features
Controlled and uncontrolled usage
Documents default values, value props, and change callbacks for form integration.
Validation state
Surfaces status, size, disabled, and option data patterns where the component supports them.
Primary API surface
OtpInput is most often configured through `length`, `size`, `variant`, `color`.
Covered behavior
Submits one native value and exposes a single input ref
Feature Demos
Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.
Preview
Interactive usage
Type or paste a code into one native input; reset returns the form value to empty.
Source
import { useState } from "react";
import "@duskmoon-dev/components/styles.css";
import { OtpInput } from "@duskmoon-dev/components/otp-input";
export function OtpInputDemo() {
const [code, setCode] = useState("");
return <form onReset={() => setCode("")}>
<label htmlFor="demo-otp">Verification code</label>
<OtpInput id="demo-otp" name="code" length={6} required
aria-describedby="demo-otp-help" onChange={(event) => setCode(event.currentTarget.value)} />
<p id="demo-otp-help">Entered {code.length} of 6 digits</p>
<button type="reset">Reset</button>
</form>;
}API
The API reference below lists every parsed exported type or interface for OtpInput. Start with `length`, `size`, `variant`, `color` for common usage.
Types:
packages/components/src/components/otp-input/OtpInput.types.tsScenarios: packages/components/src/components/otp-input/OtpInput.test.tsx| Prop | Type | Required | Description |
|---|---|---|---|
length | OtpInputLength | No | Number of decorative slots. Native input constraints default to this length. |
size | OtpInputSize | No | size configures OtpInput. |
variant | OtpInputVariant | No | variant configures OtpInput. |
color | OtpInputColor | No | color configures OtpInput. |
wrapperClassName | string | No | Additional class names for the wrapping label. |
className | string | No | Additional class names for the native input. |
Type definition
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8Type definition
"xs" | "sm" | "md" | "lg" | "xl"Type definition
"outlined" | "filled" | "underlined"Type definition
| "primary" | "secondary" | "tertiary" | "info" | "success" | "warning" | "error" | "accent" | "neutral" | "base"