Skip to Content
Sponsor

Pin Input

The PinInput component is similar to the Input component, but it is optimized for entering sequences of digits.

The most common application is for entering OTP or security codes.

Import#

  • PinInput: The component that provides context to all the pin-input fields.
  • PinInputField: The text field that user types in - must be a direct child of PinInput.

Usage#

Each input collects one number at a time. When a number is entered, focus is moved automatically to the next input, until all fields are filled.

Editable Example

Changing the size of the Input#

There are three sizes of an Input:

  • sm (24px)
  • md (32px)
  • lg (40px)
Editable Example

Adding a defaultValue#

You can set the defaultValue of the PinInput if you wish:

Editable Example

Or even a partial defaultValue:

Editable Example

Changing the placeholder#

If you donʼt like the default placeholder (), you can change that too.

Editable Example

Disable focus management#

By default, PinInput moves focus automatically to the next input once a field is filled. It also transfers focus to a previous input when Delete is pressed with focus on an empty input.

To disable this behavior, set manageFocus to false

Editable Example

AutoFill and Copy + Paste#

Try copying & pasting 1234 into any of the inputs in the example above.

By default, you can only change one input at a time, but if one of the input field receives a longer string by pasting into it, PinInput attempts to validate the string and fill the other inputs.

Editable Example

Props#

NameTypeDescriptionDefault
autoFocusbooleanIf `true`, the pin input receives focus on mount-
childrenReactNodeThe children of the pin input component-
colorSchemestring-
defaultValuestringThe default value of the pin input-
errorBorderColorstringThe border color when the input is invalid. Use color keys in `theme.colors` @example errorBorderColor = "red.500"-
focusBorderColorstringThe border color when the input is focused. Use color keys in `theme.colors` @example focusBorderColor = "blue.500"-
idstringThe base id string that will be applied to the input fields. The index of the input will be appended to this base id. @example if id="foo", the first input will have `foo-0`-
isDisabledbooleanIf `true`, the pin input component is put in the disabled state-
isInvalidbooleanIf `true`, the pin input component is put in the invalid state-
manageFocusbooleanIf `true`, focus will move automatically to the next input once filledtrue
onChange((value: string) => void)Function called on input change-
onComplete((value: string) => void)Function called when all inputs have valid values-
orientation"horizontal" | "vertical"-
placeholderstringThe placeholder for the pin input-
sizestring-
styleConfigRecord<string, any>-
valuestringThe value of the the pin input. This is the value that will be returned when the pin input is filled-
variantstring-

PinInputField#

PinInputField composes Input so you can pass all Input props.

NameTypeDescriptionDefault
colorSchemestring-
cssInterpolation<{}>The emotion's css style object-
errorBorderColorstringThe border color when the input is invalid. Use color keys in `theme.colors` @example errorBorderColor = "red.500"-
focusBorderColorstringThe border color when the input is focused. Use color keys in `theme.colors` @example focusBorderColor = "blue.500"-
isDisabledbooleanIf `true`, the form control will be disabled. This has 2 side effects: - The `FormLabel` will have `data-disabled` attribute - The form element (e.g, Input) will be disabled-
isFullWidthbooleanIf `true`, the input element will span the full width of its parent-
isInvalidbooleanIf `true`, the form control will be invalid. This has 2 side effects: - The `FormLabel` and `FormErrorIcon` will have `data-invalid` set to `true` - The form element (e.g, Input) will have `aria-invalid` set to `true`-
isLoadingbooleanIf `true`, the form control will be in its `loading` state-
isReadOnlybooleanIf `true`, the form control will be readonly-
isRequiredbooleanIf `true`, the form control will required. This has 2 side effects: - The `FormLabel` will show a required indicator - The form element (e.g, Input) will have `aria-requred` set to `true`-
orientation"horizontal" | "vertical"-
sizestring-
styleConfigRecord<string, any>-
variantstring-
Edit this page