HapplyUI

Components

Digit Input

An OTP/digit input component with configurable number of slots, error, and disabled states.


Installation

bunx @happlyui/cli@latest add digit-input

Dependencies

npm packages

  • react-otp-input

Registry dependencies

These are automatically installed when you add this component.

  • form-field-context
  • use-form-field-binding
  • happly-ui-utils

Usage

import * as DigitInput from "@/components/ui/digit-input"

<DigitInput.Root numInputs={4} onChange={setValue} value={value} />

Examples

Demo

Basic 4-digit input.

<DigitInput.Root numInputs={4} onChange={setValue} value={value} />

Has Error

Digit input in error state.

<DigitInput.Root hasError numInputs={4} onChange={setValue} value={value} />

Disabled

Disabled digit input.

<DigitInput.Root disabled numInputs={4} onChange={setValue} value={value} />

Square

Square-shaped digit input slots.

<DigitInput.Root numInputs={4} onChange={setValue} value={value} className="justify-center [&>input]:aspect-square [&>input]:w-auto" />

With Form Field

Digit input composed with FormField for consistent label and hint.

Enter the 5-digit code sent to your email.
<FormField.Root
  label="Verification Code"
  hint="Enter the 5-digit code sent to your email."
>
  <DigitInput.Root numDigits={5} />
</FormField.Root>

API Reference

DigitInput.Root

The digit input component. Wraps react-otp-input.

PropTypeDefaultDescription
numInputsnumber-Number of input slots
valuestring-Current input value
onChange(value: string) => void-Callback when the value changes
hasErrorbooleanfalseShow error styling with red ring
disabledbooleanfalseDisable all input slots

Previous
Datepicker