Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Buttons

  • Button
  • ShimmerButton
  • InteractiveHoverButton
  • RainbowButton
  • PulsatingButton
  • RippleButton
  • ButtonGroup
  • SocialButton

Basic Inputs

  • Input
  • Textarea
  • CellEditor
  • Select
  • Checkbox
  • CheckboxGroup
  • Radio
  • Switch
  • Toggle
  • Segmented
  • Slider
  • NumberField
  • ElasticSlider

Advanced Inputs

  • MathTextarea
  • QuestionEditor
  • QuestionAnswer
  • MathField
  • SecretField
  • PasswordGenerator
  • Combobox
  • RemoteSelect
  • Listbox
  • Mentions
  • InputOTP
  • Rating
  • Upload
  • RegionSelect
  • ImageCropper
  • ScopeMatrix
  • Transfer
  • Cascader
  • TreeSelect
  • RegionCascader
  • CountrySelect
  • MarkdownEditor
  • Novel editor
  • RichTextEditor
  • CodeEditor
  • IssueReporter
  • ColorPicker
  • ColorField
  • ColorSwatchPicker
  • Choicebox
  • EmojiPicker
  • VoiceRecord
  • IconPicker
  • InspectorPanel

Date and Time

  • Calendar
  • DatePicker
  • DateTimePicker
  • DateRangePicker
  • TimePicker
  • TimeField

Form Frameworks

  • Form
  • ModalForm / DrawerForm
  • ProForm
  • StepsForm
  • LoginForm
  • AuthPanel
  • ClickCaptcha
  • Label
  • Field
  • SearchForm

InputOTP

input-otp

Collects one-time codes across fixed-length slots with auto-advance, backspace, and full-code paste.

Usage

Basic usage

6-digit verification code, automatically assigned to skip spaces, backspaces, and paste the entire paragraph.

tsx
<InputOTP length={6} value={otp} onChange={setOtp} onComplete={verify} />

Group separation

groupGap Insert a horizontal line in the middle to present a 3-3 grouping vision.

tsx
<InputOTP length={6} groupGap value={otp} onChange={setOtp} />

Any character

type="text" Accepts alphanumeric redemption codes/invitation codes.

tsx
<InputOTP length={6} type="text" value={code} onChange={setCode} />

Invalid state

invalid is marked with a red border and prompts you to re-enter when the verification fails.

tsx
<InputOTP length={4} invalid value={otp} onChange={setOtp} />

When to use

Use InputOTP for fixed-length SMS or email codes, PINs, and two-factor codes. It handles segment focus, Backspace, full-code paste and splitting, and onComplete; do not recreate this with separate text inputs and regular expressions. Use Input or SecretField for unrestricted text.

Import

ts
import { InputOTP } from "@hulianui/ui"

Props

Inherits the native attributes of the root role="group" element, so id, data-*, aria-*, onFocus, and onBlur can all be passed directly.

NameTypeDefaultDescription
lengthnumber6number of segments
valuestring-controlled value
defaultValuestring""Uncontrolled initial value.
type"numeric" | "text""numeric"Numbers only (default) or any characters
disabledbooleanfalseDisables the control.
invalidbooleanfalseVerification failed status
groupGapbooleanfalseInserts a separator in the middle for a 3-3 grouping such as XXX-XXX.
namestring-Submission name. Renders an extra hidden input holding the complete value, because the segments each hold a single character and would otherwise submit N separate fields.
classNamestring-Container class name
aria-labelstring"\u9a8c\u8bc1\u7801"Accessible name; the built-in Chinese copy means “Verification code.”

Events

EventTypeDescription
onChange(value: string) => voidvalue change callback
onComplete(value: string) => voidCallback when full
onBlur(e: FocusEvent<HTMLDivElement>) => voidFires when focus leaves the whole group; moving between segments does not count. Pass field.onBlur here when using a react-hook-form Controller.

Usage guidelines

  • onComplete fires once when the final segment is filled. Put verification there instead of repeatedly checking value.length === length in onChange.
  • Pair a controlled value with onChange; without the update, the segments cannot accept input.
  • With react-hook-form, the value is a single string rather than a native input, so it must go through Controller, and field.onBlur must be passed in. Without it touchedFields never updates and a form using mode: "onBlur" or "onTouched" fails silently: focusing and leaving the field never triggers validation, and errors only appear on submit.
  • onBlur has whole-group semantics: moving focus between segments does not fire it. Per-segment blur has to be handled separately.

Related

SecretField · Combobox · Listbox · Mentions · Rating · Upload

Playground

(Enter verification code)
<InputOTP
  length={6}
  type="numeric"
  value={otp}
  onChange={setOtp}
  onComplete={verify}
/>
PreviousMentionsFormsNextRating

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Usage guidelines
    • Related
  • Playground