Skip to content

PinInput

Introduction

The PinInput component provides a secure and user-friendly interface for entering PIN codes, OTPs, or verification codes. It supports auto-focus management, masking, validation, custom lengths, variants, sizes, and full reactivity via Pulse signals. PinInput is ideal for authentication flows, secure access, and any scenario requiring multi-field code entry.

Import

tsx
import { PinInput } from '@odyssee/components';

LiveCodeEditor Examples

Basic PIN Input

Code Éditable
Résultat

With Label, Hint, and Error

Code Éditable
Résultat

Input Types: Numeric and Alphanumeric

Code Éditable
Résultat

Masked Input

Code Éditable
Résultat

Variants

Code Éditable
Résultat

Sizes

Code Éditable
Résultat

Focus Effects

Code Éditable
Résultat

States: Disabled, Readonly, Error

Code Éditable
Résultat

One-Time-Code (iOS Support)

Code Éditable
Résultat

Custom Regex Validation

Code Éditable
Résultat

OnComplete Callback

Code Éditable
Résultat

Props Table

PropTypeDefaultDescription
lengthnumber4Number of input fields (digits/characters).
valuestring | Signal<string>PIN value (can be reactive signal).
placeholderstring""Placeholder for each input field.
disabledbooleanfalseDisables all input fields.
readonlybooleanfalseMakes all input fields read-only.
requiredbooleanfalseMarks the input as required.
maskedbooleanfalseMasks input (shows password dots).
type"alphanumeric" | "numeric""alphanumeric"Restricts input to numbers or alphanumeric.
patternstringCustom regex pattern for validation.
variant"default" | "gray" | "underline""default"Visual style variant.
size"sm" | "md" | "lg""md"Size of the input fields.
focusEffect"scale" | "none"Visual effect on focus.
errorstringError message displayed below the input.
labelstringLabel displayed above the input.
hintstringOptional hint text below the input.
onChange(value: string) => voidCallback fired when the value changes.
onComplete(value: string) => voidCallback fired when all fields are filled.
onFocus(event: Event) => voidCallback fired when any input gains focus.
onBlur(event: Event) => voidCallback fired when any input loses focus.
autoCompletestringAutocomplete attribute (e.g., "one-time-code" for iOS).
classNamestringAdditional CSS classes for the root element.
idstringauto-genUnique ID for the pin input container.
...restanyOther props are spread to the root element.

Implementation Notes

  • Fully reactive: supports Pulse signals for value and state.
  • Auto-focus management: moves focus to next field on input, previous on backspace.
  • Paste support: pasting a code fills all fields.
  • Masked mode for password-like PINs.
  • Custom validation via type or pattern.
  • Variants and sizes for flexible UI integration.
  • Error, hint, and label are styled for clarity and accessibility.
  • Supports iOS one-time-code autofill via autoComplete.

Accessibility

  • Uses native <input> fields with proper labeling via for and id.
  • Keyboard navigation: arrow keys, backspace, delete, tab supported.
  • Error and hint messages are announced via text.
  • Disabled and readonly states are visually and programmatically indicated.
  • Supports ARIA attributes for status indication.
  • Paste and auto-complete behaviors are accessible.

Best Practices

  • Use length to match the expected code size (e.g., 4 or 6 digits).
  • Prefer signals for reactive value management in authentication flows.
  • Use masked for sensitive codes (PIN, password).
  • Provide clear labels, hints, and error messages for guidance.
  • Use onComplete to trigger verification or submission when code entry is finished.
  • Enable autoComplete='one-time-code' for mobile autofill support.

Released under the MIT License.