structyl

One-Time Password Field API

View component

The full prop reference for the One-Time Password Field component. A segmented input for OTP / PIN codes.

Import

tsx
import { One-TimePasswordField } from '@structyl/styled';

Props

Root

The root container for the one-time-password field. Manages state and context for all inputs.

PropTypeDefault
length#number

Number of input fields to display

6
value#string

Controlled value of the OTP field

defaultValue#string

Initial uncontrolled value

''
onValueChange#(value: string) => void

Callback fired when the OTP value changes

type#'numeric' | 'alphanumeric'

Input type constraint

'numeric'
mask#boolean

Mask input as password field when true

autoSubmit#boolean

Trigger onComplete when all fields are filled

true
disabled#boolean

Disable all input fields

onComplete#(value: string) => void

Callback fired when all OTP fields are completed and autoSubmit is true

asChild#boolean

Render as child element instead of div

className#string

CSS class name for styling

ref#React.Ref<HTMLDivElement>

Ref forwarded to root div element

Input

Individual OTP input field. Must be used inside Root. Requires an index prop.

PropTypeDefault
index#number

Position of this input in the OTP field (0-based)

className#string

CSS class name for styling

disabled#boolean

Disable this specific input field

onChange#(event: React.ChangeEvent<HTMLInputElement>) => void

Native change event handler (composed with internal handler)

onKeyDown#(event: React.KeyboardEvent<HTMLInputElement>) => void

Native keydown event handler (composed with internal arrow/backspace handler)

onFocus#(event: React.FocusEvent<HTMLInputElement>) => void

Native focus event handler (composed with internal select handler)

ref#React.Ref<HTMLInputElement>

Ref forwarded to input element

HiddenInput

Hidden input field that submits the complete OTP value as a single field. Useful for form submission.

PropTypeDefault
name#string

Name attribute for form submission

className#string

CSS class name (rarely needed for hidden input)

ref#React.Ref<HTMLInputElement>

Ref forwarded to hidden input element

Source code

If you didn't find what you need here, read the component implementation .

structyl — Accessible React Component Library