Your next page is taking shape...

Opening Your Next Page…

Loading the guide and preparing its examples for you to explore. The page will appear here automatically when it’s ready, so you can keep this view open without refreshing.

Made for Preact. Built to be yours.

Forms & Input

Input OTP

One-time passcodes with per-character slots, overlay input, patterns (digits / alphanumeric), and shadcn-parity examples. Make the expected input clear before someone interacts, and keep the current value, help text and validation feedback connected. Import it from @/components/kamod-ui/input-otp.

Source · Design reference · API reference · Theming · Styles


Interactive Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Installation

Import InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator and optional REGEXP_ONLY_DIGITS from @/components/kamod-ui/input-otp.

Install PackagesTerminal
pnpm add @kamod-ch/ui

Copy an example with @kamod-ch/ui or the matching @kamod-ch/ui/… subpath. The code block switches between those two installs. Connect The Global Theme CSS and Tailwind Source Detection before your first render.

Usage

Render one InputOTPSlot per index (0 … maxLength−1). Typing updates all slots from a single transparent input. Use pattern with REGEXP_ONLY_DIGITS or REGEXP_ONLY_DIGITS_AND_CHARS. onChange and onValueChange both receive the string.

Import SetupTypeScript
import { InputOtp } from "@kamod-ch/ui";

Choose a complete composition from the examples below; required child components and props vary by pattern.

Component Examples & Variants

Explore Input OTP in Different Contexts, from the starting pattern to the compositions below. Begin with Demo, then compare the examples that match your content, state and layout. These are working patterns to adapt, not a list of interchangeable variant values: check the API Reference before using a prop or combining behaviors. Look at the surrounding labels, supporting text and spacing as well as the component itself.

Read the Result and Its Implementation Together. Use each showcase’s Code view to inspect imports and composition, or its Prompt view to prepare a setup or adaptation brief. Try the narrow preview and local theme controls before connecting real data, and use Reset to return an example to its initial state. Keep layout changes in class utilities where appropriate; follow the Component Styles Guide for hierarchy and the Theming Guide for shared surfaces and colors. The Accessibility Notes explain what to preserve when making those changes.

Demo

Match the Code Length to the Actual Challenge. Use six InputOTPSlot positions to display one code value, optionally prefilled through defaultValue. The slots divide the presentation into readable characters while the verification flow still treats the code as one input.

Support a clear verification and retry flow, and avoid treating a fully filled input as proof that the code is valid.

src/components/InputOTPExample.tsx13 lines
import { InputOTP, InputOTPGroup, InputOTPSlot } from "@kamod-ch/ui";

const slots = [0, 1, 2, 3, 4, 5] as const;

export const Example = () => (
  <InputOTP maxLength={6} defaultValue="123456">
    <InputOTPGroup>
      {slots.map((i) => (
        <InputOTPSlot key={i} index={i} />
      ))}
    </InputOTPGroup>
  </InputOTP>
);

Usage

Group Characters to Help Scanning. Arrange two groups of three slots with a separator to make a six-character code easier to scan. The visual grouping does not add a separator character to the code that the user enters or submits.

Keep the group structure consistent with the message users receive, and test pasting a complete code as well as entering each character individually.

Interactive Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Pattern

Filter Entry without Replacing Verification. Pass an exported pattern constant to restrict the permitted characters, choosing digits or a mixed alphanumeric code. Keep that restriction consistent with the actual code issued by the service rather than only its visual example.

Explain the accepted alphabet, handle incomplete entry clearly, and avoid rejecting legitimate characters merely because the visual example uses digits.

Interactive Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Separator

Choose a Rhythm that Matches the Source. Split six slots into three groups of two when that rhythm matches the code users receive. Separators improve recognition of the displayed pattern while the stored value remains a single sequence of characters.

Keep separator marks decorative, preserve a single logical value, and verify that pasting and keyboard editing work naturally across group boundaries.

Interactive Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Disabled

Explain When Verification Cannot Proceed. Combine disabled with an existing value to show a code that is currently unavailable for editing. The filled slots preserve context, while the surrounding message should explain whether verification is pending or the entry step has ended.

Restore an editable path after a recoverable error and avoid leaving a stale code visible as if verification had succeeded.

Interactive Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Controlled

Keep Feedback Derived from the Entered Code. Pass value and update it through onChange or onValueChange when a parent owns code entry. Derive any length or completion hint from that value so the feedback remains synchronized with the visible slots.

Use the same value for display and submission, and keep request state separate so an in-flight response cannot incorrectly validate a later edit.

Interactive Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Invalid

Provide a Useful Retry Message. Apply aria-invalid to the slots when validation rejects the entered code and show the reason nearby. Visual error styling communicates which entry needs attention, while your validation flow decides whether another attempt is allowed.

Decide whether to preserve the entered value for correction or clear it deliberately, and keep focus behavior predictable after the failure.

Interactive Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Four Digits

Use Four Slots Only for a Four-Character Contract. Use four slots and a digits pattern when the issued PIN has exactly four numeric characters. The number of visible slots should match the expected value, avoiding an interface that suggests extra characters are required.

Label the field, support paste and provide a clear retry route; a shorter visual pattern does not define security requirements.

Interactive Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Alphanumeric

Make the Accepted Alphabet Clear. Use REGEXP_ONLY_DIGITS_AND_CHARS when the verification code may contain letters as well as numbers. Explain that format before entry so users do not mistake alphabetic characters for a numeric-only PIN.

Keep the displayed groups readable and test pasted values; input filtering should prevent obvious mistakes without silently changing a valid code into a different value.

Interactive Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Form

Build the Surrounding Verification Journey. Place the OTP entry in a verification card with instructions and an explicit action. Larger slots can improve readability, while the surrounding form explains which code to enter and what happens when it is submitted.

Connect submission to actual verification, provide pending and failure feedback, and make resend or change-destination actions distinct from confirming the current code.

Interactive Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width
API reference

Props and Data

Configure Input OTP using the contracts below. Read the documented options alongside the Source Definitions to understand which values your application supplies and which details the component owns. Start with a prop or helper, then follow its type link to inspect the declaration without leaving the page.

Props, slots and variants for this component.

API reference
Your API, from source

Type cards are extracted from this checkout’s TypeScript source at build time. Props inherited through HTMLAttributes, Omit or variant helpers remain references in those declarations; their fields are not flattened here. Match the reference to your installed version, and check a package’s exports before writing an import type. A type exported by a source file is not necessarily re-exported by @kamod-ch/ui.

Component Props

Read each option with its owning component. The
marker identifies required fields verified in that declaration. A ? means a field can be omitted; it does not promise a fallback value. Existing documented defaults remain alongside the descriptions. For callbacks, check the argument and return types before connecting your own state or services.
@kamod-ch/ui/input-otp6.0 KB min · 2.0 KB gzipSignals: direct@preact/signals

InputOTP

InputOTPProps

InputOTP documented props
Prop / typeDescription
autoComplete
stringInputOTPProps

Configure autoComplete for InputOTP. Compare its accepted type with the Usage Guidance before supplying a value.

Default
"one-time-code"
children
ComponentChild[] | ComponentChildInputOTPProps

Configure children for InputOTP. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
class
string | SignalLike<string | undefined>InputOTPProps

Configure class for InputOTP. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
defaultValue
stringInputOTPProps

Configure defaultValue for InputOTP. Compare its accepted type with the Usage Guidance before supplying a value.

Default
""
dir
"auto" | "rtl" | "ltr" | SignalLike<"auto" | "rtl" | "ltr" | undefined>InputOTPProps

Configure dir for InputOTP. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
disabled
booleanInputOTPProps

Configure disabled for InputOTP. Compare its accepted type with the Usage Guidance before supplying a value.

Default
false
id
string | (SignalLike<string | undefined> & string)InputOTPProps

Configure id for InputOTP. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
maxLength
numberInputOTPProps

Configure maxLength for InputOTP. Compare its accepted type with the Usage Guidance before supplying a value.

Default
6
name
stringInputOTPProps

Configure name for InputOTP. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
onChange
((value: string) => void)InputOTPProps

Configure onChange for InputOTP. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
onValueChange
((value: string) => void)InputOTPProps

Configure onValueChange for InputOTP. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
pattern
RegExpInputOTPProps

Configure pattern for InputOTP. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
value
stringInputOTPProps

Configure value for InputOTP. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—

InputOTPGroup

InputOTPGroupProps

InputOTPGroup documented props
Prop / typeDescription
children
ComponentChild[] | ComponentChildInputOTPGroupProps

Configure children for InputOTPGroup. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
class
string | SignalLike<string | undefined>InputOTPGroupProps

Configure class for InputOTPGroup. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—

InputOTPSeparator

InputOTPSeparatorProps

InputOTPSeparator documented props
Prop / typeDescription
children
ComponentChild[] | ComponentChildInputOTPSeparatorProps

Configure children for InputOTPSeparator. Compare its accepted type with the Usage Guidance before supplying a value.

Default
"-"
class
string | SignalLike<string | undefined>InputOTPSeparatorProps

Configure class for InputOTPSeparator. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—

InputOTPSlot

InputOTPSlotProps

InputOTPSlot documented props
Prop / typeDescription
class
string | SignalLike<string | undefined>InputOTPSlotProps

Configure class for InputOTPSlot. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
index
numberInputOTPSlotProps

Configure index for InputOTPSlot. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—

Data Type Reference

Expand a card to inspect and copy the exact declaration. The code header identifies its repository file; follow imported or inherited types in the Implementation Source when you need the complete dependency chain. Required-field summaries cover fields declared directly in that type. Source-only helpers and inferred schema outputs describe the local implementation, not additional props you can pass to every component.

InputOTP Props

11 declared fields
InputOTPProps
Exported Source Declaration from InputOTP.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of InputOTPProps before adapting it.

InputOTPGroup Props

1 declared field
InputOTPGroupProps
Exported Source Declaration from InputOTPGroup.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of InputOTPGroupProps before adapting it.

InputOTPSeparator Props

1 declared field
InputOTPSeparatorProps
Exported Source Declaration from InputOTPSeparator.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of InputOTPSeparatorProps before adapting it.

InputOTPSlot Props

1 declared field
InputOTPSlotProps
Exported Source Declaration from InputOTPSlot.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of InputOTPSlotProps before adapting it.
Required fields
index

InputOTPContextValue

6 declared fields
InputOTPContextValue
Exported Source Declaration from input-otp-context.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of InputOTPContextValue before adapting it.
Required fields
value, maxLength, disabled, focused, activeIndex, inputRef

Accessibility

Build the Complete Interaction, Including the Parts Outside Input OTP. The notes below distinguish the current implementation from the labels, content and behavior your application supplies. Start with the Live Preview, check the Props and Data Reference, and test the finished composition with real content rather than assuming that an unchanged visual example covers every use case.

Built-in Behavior and Defaults

InputOTP renders one real text input over visual slots. The input defaults to the accessible name One-time password and uses one-time-code autofill. Slot count is visual presentation, not a set of separately focusable fields.

Labels and Relationships

Provide a context-specific aria-label and matching visible instruction, such as the code's expected length and delivery channel. The component explicitly forwards id, name and its label to the input; other root attributes are not necessarily forwarded to that input.

Keyboard and Focus

Preserve full-code paste, selection and normal text editing. Numeric filtering can request a numeric keyboard, but do not block paste from password managers or messages. Use a separate confirmation action when verifying a code has a consequential outcome.

States and Integration Details

Do not put a tab stop on each visual slot or assume an error description attached to the wrapper is attached to the real input. Explain expired codes and resend timing in text, and avoid clearing a nearly completed code on an unrelated rerender.

Verify the Complete Interaction

Check Behavior as Well as Markup. Work through these scenarios in the application where the component will be used. Automated checks can help find structural problems; also review the reading experience with a screen reader, keyboard focus and the actual feedback from your application.

  1. Tab once into the code input, paste a complete code, then edit a character in the middle.
  2. Inspect the actual input's accessible name and any validation relationship after customization.
  3. Try autofill, an expired code, resend and a narrow viewport while keeping instructions available.

Recheck the result after changing Theme Tokens, translations or class overrides. Include text enlargement, narrow layouts and reduced-motion settings where animation is present. Inspect the Component Source when a behavior differs from your expectation; a role or state attribute does not implement keyboard interaction by itself.

For background, read the WAI-ARIA Authoring Guidance and Keyboard Interface Guidance. These explain the patterns; verify browser and assistive-technology behavior for the implementation and audience you actually support.

Take the Next Useful Step

You have the pieces. Put them into one real interaction, keep its state in one place, and check the result with the content your application will actually show.

Connect the Foundation

Return to Choose and Compose Components to connect this reference to a working screen. Keep global CSS in one entrypoint and import only the components that screen needs.

Build the Surrounding Screen

Find a neighboring interaction in the Component Library, or start with a complete Block. Replace sample content and destinations before refining the layout; a local class change can stay with the composition.

Make the Result Hold Up

Use shared theme roles for changes that belong everywhere. Then review the whole journey: keyboard focus, long labels, narrow screens and a clear way to recover when something fails.

Keep a link to the source and note your intentional changes. Your next edit should begin with a clear decision, not another search.