DocsBlog

Get Started

Components

Data Grid

Signals

Styling

Theming

↑↓Navigate
↵Select
EscClose
  • 1.8.0

  • Day

    Night

    Preview

    Switch mode
  • cerberus

    acheron

    elysium

    oceanus

Get Started
Components
Data Grid
Signals
Styling
Theming

Concepts

OverviewCompositionCerberus ContextTesting

Layout

Aspect RatioBleedBoxCenterContainerContainer QueryDividerFlexFloatGridGroupLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTA ModalDate PickerDialogFieldFieldsetFile UploaderIconButtonInputLoading StatesMarqueeMenuNotificationsNumber InputPaginationPin InputPopoverProgress IndicatorsPrompt ModalRadioRatingSelectSliderSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFormat Relative TimeFrameHighlightJSON Tree ViewLocalePortalPresenceShowSwapsplitPropsTheme

Pin Input

Enter and manage secure multi-character codes with the PinInput component.

  • npm
  • source
  • recipe
  • Ark
View as Markdown
Open this page in Markdown
Anthropic
Open in Claude
Ask questions about this page
OpenAI
Open in ChatGPT
Ask questions about this page

Import

import { PinInput } from '@cerberus/react'

Usage

The PinInput component lets users enter fixed-length codes (such as verification codes or PINs) one character at a time. It manages focus movement between inputs and aggregates the value for you.

Loading example...

Blur on complete

By default, the last input maintains focus when filled, and we invoke the onValueComplete callback. To blur the last input when the user completes the input, set the prop blurOnComplete to true.

Loading example...

Count

The count prop determines the number of individual input boxes rendered. This is useful for specifying the length of the PIN or code the user needs to enter.

Loading example...

Sizes

The PinInput component supports different sizes to accommodate various design requirements.

Failed to load code file: components/pin-input/sizes.demo.tsx

Customization

You can customize the PinInput component using style props or the primitive components.

Loading example...

Primitives

ComponentDescription
PinInputRootRoot context provider for the family.
PinInputLabelAccessible label element.
PinInputControlWraps the individual input boxes.
PinInputInputA single character input field.
PinInputHiddenInputAggregated hidden input used in forms.

Parts

The PinInputParts API is an object containing the full family of components.

NameDescription
RootThe PinInputRoot component which is the provider for the family.
LabelThe PinInputLabel component.
ControlThe PinInputControl layout wrapper.
InputThe PinInputInput component.
HiddenInputThe PinInputHiddenInput component.

API

Root

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.
autoFocusbooleanfalseundefinedWhether to auto-focus the first input.
autoSubmitbooleanfalseundefinedWhether to auto-submit the owning form when all inputs are filled.
blurOnCompletebooleanfalseundefinedWhether to blur the input when the value is complete
countnumberfalseundefinedThe number of inputs to render to improve SSR aria attributes.
This will be required in next major version.
defaultValuestring[]falseundefinedThe initial value of the the pin input when rendered.
Use when you don't need to control the value of the pin input.
disabledbooleanfalseundefinedWhether the inputs are disabled
formstringfalseundefinedThe associate form of the underlying input element.
idstringfalseundefinedThe unique identifier of the machine.
idsPartial<{ root: string, hiddenInput: string, label: string, control: string, input: (id: string) => string }>falseundefinedThe ids of the elements in the pin input. Useful for composition.
invalidbooleanfalseundefinedWhether the pin input is in the invalid state
maskbooleanfalseundefinedIf true, the input's value will be masked just like type=password
namestringfalseundefinedThe name of the input element. Useful for form submission.
onValueChange(details: ValueChangeDetails) => voidfalseundefinedFunction called on input change
onValueComplete(details: ValueChangeDetails) => voidfalseundefinedFunction called when all inputs have valid values
onValueInvalid(details: ValueInvalidDetails) => voidfalseundefinedFunction called when an invalid value is entered
otpbooleanfalseundefinedIf true, the pin input component signals to its fields that they should
use autocomplete="one-time-code".
patternstringfalseundefinedThe regular expression that the user-entered input value is checked against.
placeholderstringfalse"○"The placeholder text for the input
readOnlybooleanfalseundefinedWhether the pin input is in the valid state
requiredbooleanfalseundefinedWhether the pin input is required
sanitizeValue(value: string) => stringfalseundefinedFunction to sanitize pasted values before validation.
Useful for stripping dashes, spaces, or other formatting.
selectOnFocusbooleanfalseundefinedWhether to select input value when input is focused
translationsIntlTranslationsfalseundefinedSpecifies the localized strings that identifies the accessibility elements and their states
type'numeric' | 'alphanumeric' | 'alphabetic'false"numeric"The type of value the pin-input should allow
valuestring[]falseundefinedThe controlled value of the the pin input.

Data Attributes

AttributeDescription / Value
data-scopepin-input
data-partroot
data-invalidPresent when invalid
data-disabledPresent when disabled
data-completePresent when the pin-input value is complete
data-readonlyPresent when read-only

Control

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

HiddenInput

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Input

Props

PropTypeRequiredDefaultDescription
indexnumbertrueundefinedundefined
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Data Attributes

AttributeDescription / Value
data-scopepin-input
data-partinput
data-disabledPresent when disabled
data-completePresent when the input value is complete
data-filled
data-indexThe index of the item
data-invalidPresent when invalid

Label

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Data Attributes

AttributeDescription / Value
data-scopepin-input
data-partlabel
data-invalidPresent when invalid
data-disabledPresent when disabled
data-completePresent when the label value is complete
data-requiredPresent when required
data-readonlyPresent when read-only

RootProvider

Props

PropTypeRequiredDefaultDescription
valueUsePinInputReturntrueundefinedundefined
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Context

API:

PropertyTypeDescription
valuestring[]The value of the input as an array of strings.
valueAsStringstringThe value of the input as a string.
completebooleanWhether all inputs are filled.
countnumberThe number of inputs to render
itemsnumber[]The array of input values.
setValue(value: string[]) => voidFunction to set the value of the inputs.
clearValueVoidFunctionFunction to clear the value of the inputs.
setValueAtIndex(index: number, value: string) => voidFunction to set the value of the input at a specific index.
focusVoidFunctionFunction to focus the pin-input. This will focus the first input.

Accessibility

Keyboard Support

KeyDescription
ArrowLeftMoves focus to the previous input
ArrowRightMoves focus to the next input
BackspaceDeletes the value in the current input and moves focus to the previous input
DeleteDeletes the value in the current input
Control + VPastes the value into the input fields

On this page

  • Import
  • Usage
  • Blur on complete
  • Count
  • Sizes
  • Customization
  • Primitives
    • Parts
  • API
    • Root
      • Props
      • Data Attributes
    • Control
      • Props
    • HiddenInput
      • Props
    • Input
      • Props
      • Data Attributes
    • Label
      • Props
      • Data Attributes
    • RootProvider
      • Props
    • Context
  • Accessibility
    • Keyboard Support
Edit this page on Github