Data Entryduskmoonimplemented1 demos

OtpInput

OtpInput captures an OTP or PIN through one native text input and decorative slots.

Import@duskmoon-dev/components/otp-input
5API sections
6documented props
3behavior scenarios
Key API
lengthsizevariantcolorwrapperClassName

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

Entered 0 of 6 digits

Interactive usage

authored

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
OtpInputPropsinterface extends Omit< ComponentProps<"input">, "children" | "className" | "size" | "type" >
PropTypeRequiredDescription
lengthOtpInputLengthNoNumber of decorative slots. Native input constraints default to this length.
sizeOtpInputSizeNosize configures OtpInput.
variantOtpInputVariantNovariant configures OtpInput.
colorOtpInputColorNocolor configures OtpInput.
wrapperClassNamestringNoAdditional class names for the wrapping label.
classNamestringNoAdditional class names for the native input.
OtpInputLengthtype
Type definition
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
OtpInputSizetype
Type definition
"xs" | "sm" | "md" | "lg" | "xl"
OtpInputVarianttype
Type definition
"outlined" | "filled" | "underlined"
OtpInputColortype
Type definition
| "primary" | "secondary" | "tertiary" | "info" | "success" | "warning" | "error" | "accent" | "neutral" | "base"