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 preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthInstallation
Import InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator and optional REGEXP_ONLY_DIGITS from @/components/kamod-ui/input-otp.
pnpm add @kamod-ch/uiCopy 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 { 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.
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 preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthPattern
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 preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthSeparator
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 preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthDisabled
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 preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthControlled
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 preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthInvalid
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 preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthFour 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 preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthAlphanumeric
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 preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthForm
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 preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthProps 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.
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
? 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.InputOTP
InputOTPProps
| Prop / type | Description |
|---|---|
autoComplete | Configure
|
children | Configure
|
class | Configure
|
defaultValue | Configure
|
dir | Configure
|
disabled | Configure
|
id | Configure
|
maxLength | Configure
|
name | Configure
|
onChange | Configure
|
onValueChange | Configure
|
pattern | Configure
|
value | Configure
|
InputOTPGroup
InputOTPGroupProps
| Prop / type | Description |
|---|---|
children | Configure
|
class | Configure
|
InputOTPSeparator
InputOTPSeparatorProps
| Prop / type | Description |
|---|---|
children | Configure
|
class | Configure
|
InputOTPSlot
InputOTPSlotProps
| Prop / type | Description |
|---|---|
class | Configure
|
index | Configure
|
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 fieldsInputOTPPropsInputOTP.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 fieldInputOTPGroupPropsInputOTPGroup.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 fieldInputOTPSeparatorPropsInputOTPSeparator.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 fieldInputOTPSlotPropsInputOTPSlot.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of InputOTPSlotProps before adapting it.indexInputOTPContextValue
6 declared fieldsInputOTPContextValueinput-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.value, maxLength, disabled, focused, activeIndex, inputRefAccessibility
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.
- Tab once into the code input, paste a complete code, then edit a character in the middle.
- Inspect the actual input's accessible name and any validation relationship after customization.
- 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.
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.