For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/en/components/input-otp.md.

InputOTP

Enter and paste verification codes.

Basic usage

Completed: —
basic.tsx
import { InputOTP, Space, Text } from '@ifhover/leaf-ui';

import { useState } from 'react';

export function InputOTPBasic() {
  const [value, setValue] = useState('');
  const [complete, setComplete] = useState('');
  return (
    <Space direction="vertical" align="stretch">
      <InputOTP value={value} onChange={setValue} onComplete={setComplete} />
      <output>
        <Text tone="muted">Completed: {complete || '—'}</Text>
      </output>
    </Space>
  );
}

More examples

Letters and digits
Masked characters
Disabled
advanced.tsx
import { InputOTP, Space, Text } from '@ifhover/leaf-ui';

export function InputOTPOptions() {
  return (
    <Space direction="vertical" align="stretch">
      <Text tone="muted">Letters and digits</Text>
      <InputOTP
        mode="alphanumeric"
        length={8}
        separator={(index) => (index === 3 ? <span>—</span> : null)}
      />
      <Text tone="muted">Masked characters</Text>
      <InputOTP length={4} mask size="lg" />
      <Text tone="muted">Disabled</Text>
      <InputOTP defaultValue="123456" disabled />
    </Space>
  );
}

Usage

Preserves one input for paste and one-time-code autofill. onComplete indicates complete input; validate the code on your server.

Types

Import these types for data, callbacks and refs.

import type { InputOTPProps } from '@ifhover/leaf-ui';

InputOTPProps API

PropertyTypeDefaultDescription
lengthnumber6Code character count
valuestring—Controlled value
defaultValuestring''Initial value, restored by uncontrolled form resets
onChange(value: string) => void—Value change callback
onComplete(value: string) => void—Called when input is complete
mode'numeric' | 'alphanumeric''numeric'Display mode or allowed characters
maskboolean | stringfalseMask displayed characters
separator(index: number) => ReactNode—Separator by position
size'sm' | 'md' | 'lg''md'Size or spacing preset
status'error' | 'warning'—Display state