Build faster with Premium Chakra UI Components 💎

Learn more
Skip to Content
DocsPlaygroundGuidesBlog
Sponsor

Pin Input

Used to capture a pin code or otp from the user

SourceStorybookRecipeArk

Setup

If you don't already have the snippet, run the following command to add the pin-input snippet

chakra snippet add pin-input

The snippet includes a closed component composition for the PinInput component.

Usage

import { PinInput } from "@/components/ui/pin-input"
<PinInput />

Examples

Sizes

Use the size prop to change the size of the pin input component.

One time code

Use the otp prop to make the pin input component behave like a one-time code input. This helps improve the user experience when entering OTP codes.

Mask

Use the mask prop to obscure the entered pin code.

Placeholder

Use the placeholder prop to add a placeholder to the pin input component.

Field

Here's an example of how to compose the Field and the PinInput components

Hook Form

Here's an example of how to compose the Field and the PinInput components with react-hook-form

Controlled

Use the value and onValueChange props to control the value of the pin input

Attached

Use the attached prop to attach the pin input to the input field

Alphanumeric

Use the type prop to allow the user to enter alphanumeric characters. Values can be either alphanumeric, numeric, or alphabetic

Props

Root

PropDefaultType
placeholder '\'○\''
string

The placeholder text for the input

type '\'numeric\''
'numeric' | 'alphabetic' | 'alphanumeric'

The type of value the pin-input should allow

colorPalette 'gray'
'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'

The color palette of the component

size 'md'
'lg' | 'md' | 'sm' | 'xs'

The size of the component

variant 'outline'
'outline' | 'filled' | 'flushed'

The variant of the component

asChild
boolean

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

For more details, read our Composition guide.
autoFocus
boolean

Whether to auto-focus the first input.

blurOnComplete
boolean

Whether to blur the input when the value is complete

defaultValue
string[]

The initial value of the pin input when it is first rendered. Use when you do not need to control the state of the pin input

disabled
boolean

Whether the inputs are disabled

form
string

The associate form of the underlying input element.

id
string

The unique identifier of the machine.

ids
Partial<{ root: string hiddenInput: string label: string control: string input(id: string): string }>

The ids of the elements in the pin input. Useful for composition.

invalid
boolean

Whether the pin input is in the invalid state

mask
boolean

If `true`, the input's value will be masked just like `type=password`

name
string

The name of the input element. Useful for form submission.

onValueChange
(details: ValueChangeDetails) => void

Function called on input change

onValueComplete
(details: ValueChangeDetails) => void

Function called when all inputs have valid values

onValueInvalid
(details: ValueInvalidDetails) => void

Function called when an invalid value is entered

otp
boolean

If `true`, the pin input component signals to its fields that they should use `autocomplete="one-time-code"`.

pattern
string

The regular expression that the user-entered input value is checked against.

readOnly
boolean

Whether the pin input is in the valid state

required
boolean

Whether the pin input is required

selectOnFocus
boolean

Whether to select input value when input is focused

translations
IntlTranslations

Specifies the localized strings that identifies the accessibility elements and their states

value
string[]

The value of the the pin input.

Previous

Password Input

Next

Popover