DocsBlog
  • 0.25.3

  • light

    dark

    system

    Switch mode
  • Cerberus

    Acheron

    Elysium

Get Started
Components
Styling
Theming

Concepts

OverviewCompositionTesting

Layout

Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFrameHighlightJSON Tree ViewLocaleLocal StoragePortalPresenceShowsplitPropsTheme

Pin Input

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

  • npm
  • source
  • recipe
  • Ark
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.

Copy
import { PinInput, Field } from '@cerberus/react'
import { HStack } from 'styled-system/jsx'
export function StaticPreview() {
return (
<HStack w="1/2">
<Field label="Enter PIN">
<PinInput />
</Field>
</HStack>
)
}

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.

Copy
import { PinInput } from '@cerberus/react'
import { HStack } from 'styled-system/jsx'
export function StaticPreview() {
return (
<HStack w="1/2">
<PinInput blurOnComplete />
</HStack>
)
}

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.

Copy
import { PinInput, Field } from '@cerberus/react'
import { HStack } from 'styled-system/jsx'
export function CountPreview() {
return (
<HStack w="1/2">
<Field label="5 Digits">
<PinInput placeholder={undefined} count={5} />
</Field>
</HStack>
)
}

Sizes

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

Copy
import { PinInput, Field } from '@cerberus/react'
import { HStack } from 'styled-system/jsx'
export function SizesPreview() {
return (
<HStack w="1/2">
<Field label="Medium">
<PinInput size="md" />
</Field>
<Field label="Large">
<PinInput size="lg" />
</Field>
</HStack>
)
}

Primitives

You can utilize the primitive components or the css prop to customize the PinInput component.

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.
Copy
import { PinInputParts } from '@cerberus/react'
import { HStack } from 'styled-system/jsx'
function CustomPreview() {
return (
<HStack w="1/2">
<PinInputParts.Root
css={{
w: 'full',
}}
>
<PinInputParts.Control
css={{
transform: 'translateX(-4px)',
}}
>
{Array.from({ length: 4 }, (_, index) => (
<PinInputParts.Input
key={index}
index={index}
css={{
border: '2px solid',
borderColor: 'black',
borderRadius: 'md',
h: '24',
w: '24',
textAlign: 'center',
fontSize: 'lg',
lineHeight: '12',
'&:focus': {
borderColor: 'danger.bg.initial',
boxShadow: '0 0 0 3px rgba(255, 69, 58, 0.6)',
},
}}
/>
))}
</PinInputParts.Control>
<PinInputParts.HiddenInput />
</PinInputParts.Root>
</HStack>
)
}

API

PinInput

The PinInput component is an abstraction over the primitive parts and exposes all Ark UI Root props. Below is a reference table for convenience (see the Ark UI Pin Input API for authoritative details).

NameDefaultDescription
asChildUse the provided child element as the rendered element.
autoFocusAuto‑focus the first input on mount.
blurOnCompleteBlur the last input when the value becomes complete.
countNumber of inputs to render (improves SSR a11y; will become required in next major).
defaultValueUncontrolled initial value array (e.g. ['1','2','3']).
disabledDisable the entire pin input.
dirltrText direction; affects arrow key navigation.
formId of an external form to associate the hidden input with.
idBase id used to derive ids for parts.
idsObject of element id overrides for composition.
invalidMark the pin input as invalid. Adds data-invalid.
maskMask each input character similar to a password field.
nameName attribute for the hidden input (form submission).
onValueChangeFired whenever any input value changes. Provides { value, valueAsString }.
onValueCompleteFired when all inputs have valid values (typing or paste).
onValueInvalidFired when an invalid value is entered (fails type or pattern).
otpEnables one‑time‑code autocomplete optimizations (autocomplete="one-time-code").
patternRegular expression the characters must satisfy.
placeholder"â—‹"Placeholder character shown in empty inputs.
readOnlyMake inputs read‑only.
requiredMark the inputs as required.
selectOnFocusSelect the existing character when an input gains focus.
translationsLocalized strings for accessibility / messages.
type"numeric"Allowed character set: numeric, alphabetic, or alphanumeric.
valueControlled value array (set length to number of inputs).

The PinInput component also accepts standard DOM props for the root element and mirrors the Ark UI Root behavior.

The PinInput is an abstraction of the underlying Ark UI primitive Root component.

Parts

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

Note

It is best to only use the PinInputParts if you are building a custom solution. Importing object-based components can increase bundle size because every part is included.

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

On this page

  • Edit this page on Github
Cerberus Design System | Docs