Fidely UI v1 beta is now available!. 🚀

Pin Input

Used to capture a pin code or otp from the user

Usage

import { PinInput } from '@fidely-ui/react'
<PinInput.Root>
  <PinInput.HiddenInput />
  <PinInput.Control>
    <PinInput.Input />
  </PinInput.Control>
</PinInput.Root>

Examples

Sizes

Pass the size prop to the PinInput.Root component to change the size of the pin input component

OTP

Pass the otp prop to the PinInput.Root component to indicate that the input is for a one-time password (OTP).

Placeholder

Pass the placeholder prop to the PinInput.Root component to define placeholder text for each input field.

Mask

Pass the mask prop to the PinInput.Root component to mask the input value (e.g., for sensitive codes).

Blur on complete

By default, the last input remains focused after the user fills all fields, and the onValueComplete callback is invoked.

To automatically blur the input after completion, set blurOnComplete to true.

With Field

The Field component helps manage form-related state and accessibility attributes of a pin input.

It includes handling ARIA labels, helper text, and error text to ensure proper accessibility.

Additional Info

With alphanumeric

Pass the type prop to the PinInput.Root component to allow the user to enter alphanumeric characters.

Values can be either alphanumeric, numeric, or alphabetic

With Controlled

Pass the value and onValueChange props to the PinInPut.Root component to control the value of the pin input

Props

Root

PropTypeDefaultDescription
placeholderstringoThe placeholder text for each input.
type'numeric' | 'alphabetic' | 'alphanumeric''numeric'The type of value the pin input should allow.
colorPalette"red" | "blue" | "green" | "purple" | "orange" | "gray"-The color palette of the component.
size'2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl''md'The size of the component.
variant'outline' | 'subtle' | 'flushed''outline'The visual variant of the component.
asReact.ElementType-The underlying element to render.
asChildbooleanfalseUse the provided child element as the rendered element, merging their props and behavior.
unstyledbooleanfalseRemoves all default styling from the component.
autoFocusbooleanfalseAutomatically focuses the first input on mount.
blurOnCompletebooleanfalseWhether to blur the input when all fields are filled.
countnumber4Number of input fields to render.
defaultValuestring[][]The initial value of the pin input when uncontrolled.
disabledbooleanfalseDisables all inputs when set to true.
formstring-The associated form of the underlying input element.
idstring-The unique identifier for the pin input root.
idsPartial<{ root: string; hiddenInput: string; label: string; control: string; input: (id: string) => string; }>-Custom IDs for pin input elements. Useful for advanced composition.
invalidbooleanfalseMarks the input as invalid.
maskbooleanfalseIf true, input values are masked (e.g., password dots).
namestring-The name of the input element for form submission.
onValueChange(details: ValueChangeDetails) => void-Called when any input value changes.
onValueComplete(details: ValueChangeDetails) => void-Called when all input fields have valid values.
onValueInvalid(details: ValueInvalidDetails) => void-Called when an invalid value is entered.
otpbooleanfalseEnables autocomplete="one-time-code" for OTP entry.
patternstring-A regular expression pattern the value must match.
readOnlybooleanfalseMakes all inputs read-only.
requiredbooleanfalseMarks the input as required.
selectOnFocusbooleanfalseAutomatically selects the input’s value when focused.
translationsIntlTranslations-Provides localized strings for accessibility and internationalization.
valuestring[][]The controlled value of the pin input.

Input

PropTypeDefaultDescription
indexnumber-The index of the current input (0-based).
asChildbooleanfalseUse the provided child element as the default rendered element, combining their props and behavior.

Control and Label

PropTypeDefaultDescription
asChildbooleanfalseUse the provided child element as the default rendered element, combining their props and behavior.

On this page