For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/ui/components/input-otp.md.
lynx-ui logo
lynx-ui
  • English
  • InputOTP

    A headless, configurable-length OTP and PIN input for ReactLynx. InputOTP owns keyboard, focus, deletion, paste, filtering, and value state through one hidden native input. Consumers compose the visible field with InputOTPSlot.
    Info

    You can check the source code to understand how it works, and you're welcome to submit PRs to enhance its capabilities.

    Basic Usage

    Build a controlled six-character code field with autofocus and completion handling.

    Examples

    Capabilities

    Explore input types, render props, states, masking, separators, and keyboard avoidance.

    Keyboard Aware

    Keep a code field near the bottom of the page visible above the software keyboard.

    RTL

    Let the code field inherit right-to-left direction from its surrounding layout.

    Structure

    <InputOTP length={slotCount}>
      {Array.from({ length: slotCount }, (_, index) => (
        <InputOTPSlot index={index} />
      ))}
    </InputOTP>

    Component API

    InputOTP

    Props for InputOTP.

    autoFocusiOSAndroidHarmony
    Typeboolean·Defaultfalse
    Focus the hidden input after mounting.
    classNameiOSAndroidHarmony
    Typestring
    className
    defaultValueiOSAndroidHarmony
    Typestring
    Initial value in uncontrolled mode.
    disablediOSAndroidHarmony
    Typeboolean·Defaultfalse
    Disable keyboard input and focus.
    inputTypeiOSAndroidHarmony
    TypeInputOTPInputType·Default"numeric"
    Character set accepted by the hidden native input.
    invalidiOSAndroidHarmony
    Typeboolean·Defaultfalse
    Expose the invalid state to render props and the ui-invalid UI variant.
    lengthiOSAndroidHarmony
    Typenumber·Default6
    Positive number of OTP or PIN characters. Invalid values fall back to 6.
    onBluriOSAndroidHarmony
    Type() => void
    Called when the hidden input loses focus.
    onChangeiOSAndroidHarmony
    Type(value: string) => void
    Called after the normalized value changes.
    onCompleteiOSAndroidHarmony
    Type(value: string) => void
    Called when the value transitions from incomplete to complete.
    onFocusiOSAndroidHarmony
    Type() => void
    Called when the hidden input gains focus.
    ref
    TypeForwardedRef<InputOTPRef>
    styleiOSAndroidHarmony
    TypeCSSProperties
    style
    valueiOSAndroidHarmony
    Typestring
    Controlled value. Characters outside inputType are discarded.
    childreniOSAndroidHarmony
    TypeReactNode | ((state: InputOTPRenderProps) => ReactNode)
    InputOTPSlot children, or a render function receiving the field state. InputOTP does not create slots automatically.

    State-based styling & rendering

    This component exposes runtime states through one or both of the following channels. The table lists only the channels available for each state:

    • UI variant class — when supported, a class like ui-<state> is toggled on the corresponding component node for selectors such as .ui-<state> { ... }.
    • Render-prop field — when supported and children is a function, the state is passed in via children({ <state>: boolean, ... }) for runtime-driven rendering.

    UI variants applied by InputOTP based on its render state.

    Class NameRender PropTypeDescription
    ui-completecompletebooleanWhether every slot is filled. Applied to the root when every slot is filled.
    ui-disableddisabledbooleanWhether input is disabled. Applied to the root while input is disabled.
    ui-focusedfocusedbooleanWhether the hidden native input is focused. Applied to the root while the hidden input is focused.
    ui-invalidinvalidbooleanWhether the field is invalid. Applied to the root while the value is invalid.

    InputOTPSlot

    Props for an individual InputOTP visual slot.

    classNameiOSAndroidHarmony
    Typestring
    className
    indexiOSAndroidHarmony
    Typenumber
    Zero-based index used to read the corresponding InputOTP character.
    styleiOSAndroidHarmony
    TypeCSSProperties
    style
    childreniOSAndroidHarmony
    TypeReactNode | ((state: InputOTPSlotRenderProps) => ReactNode)
    Custom slot content. A render function receives the slot state. When omitted, InputOTPSlot renders its character and visual caret.

    UI variants applied by InputOTPSlot based on its render state.

    Class NameRender PropTypeDescription
    ui-completecompletebooleanWhether every slot in the field is filled. Applied to every slot when the field is complete.
    ui-disableddisabledbooleanWhether input is disabled. Applied to the slot while input is disabled.
    ui-filledfilledbooleanWhether this slot contains a character. Applied to slots that contain a character.
    ui-focusedfocusedbooleanWhether this is the focused slot that contains the visual caret. Applied to the slot that contains the visual caret.
    ui-invalidinvalidbooleanWhether the field is invalid. Applied to the slot while the value is invalid.

    InputOTPRef

    Imperative methods exposed by InputOTP.

    bluriOSAndroidHarmony
    Type() => Promise<void>
    Blur the hidden native input and dismiss the keyboard.
    cleariOSAndroidHarmony
    Type() => Promise<void>
    Clear the current uncontrolled value. In controlled mode, update the value prop from the onChange callback.
    focusiOSAndroidHarmony
    Type() => Promise<void>
    Focus the hidden native input and show the configured keyboard.
    getValueiOSAndroidHarmony
    Type() => string
    Return the currently displayed value.
    setValueiOSAndroidHarmony
    Type(value: string) => Promise<void>
    Replace the current uncontrolled value. In controlled mode, this requests the next value through onChange and the value prop remains authoritative. Unsupported characters are discarded.

    Supporting Types

    InputOTPInputType

    InputOTPInputType
    Typealphabetic | numeric | alphanumeric
    Character set accepted by InputOTP.

    InputOTPLength

    InputOTPLength
    Typenumber
    Positive number of slots managed by InputOTP.
    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.