PinInput

PinInput is a component used to capture pin codes or OTP (One-Time Password) inputs.

Usage

import { PinInput } from "@yamada-ui/react"
<PinInput.Root />

Change Variant

Change Size

Change Color Scheme

Set Default Value

To set a default value, set a string to defaultValue.

Change Placeholder

To change the placeholder, set a string to placeholder.

Change Number of Fields

To change the number of fields, set a number to items.

Change Type

By default, only numeric input is allowed. To support alphanumeric, set type to alphanumeric.

Use as One-Time Password

To use as a one-time password (autocomplete="one-time-code"), set otp to true.

Mask Entered Value

To mask the entered value, set mask to true.

Disabled

To disable the input, set disabled to true.

Read-Only

To make read-only, set readOnly to true.

Invalid

To make invalid, set invalid to true.

Change Border Color

To change the border color, set focusBorderColor or errorBorderColor to the color.

Set Action on Completion

To set the action on completion, use the onComplete property.

Disable Focus Management

By default, when a field is entered, the focus automatically moves to the next field. Also, when the BackSpace key is pressed, the focus moves to the previous field. To disable this control, set manageFocus to false.

Customize Field

Control

Props

Accessibility

If you are not using Field.Root, set aria-label or aria-labelledby to PinInput.Root.

<PinInput.Root aria-label="Please one-time password" />
<VStack gap="sm">
  <Text as="h3" id="label">
    Please one-time password
  </Text>

  <PinInput.Root aria-labelledby="label" />
</VStack>

Keyboard Navigation

KeyDescriptionState
TabMove the focus to the next item.-
ArrowRightMove the focus to the next item.-
ArrowLeftMove the focus to the previous item.-

ARIA Roles and Attributes

ComponentRole and AttributesUsage
PinInput.Rootrole="group"Indicates that this is a group.
PinInput.Fieldaria-invalidSet to "true" if invalid is set.
aria-disabledSet to "true" if disabled is set.
aria-describedbyIf PinInput.Field is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id.
aria-readonlySet to "true" if readOnly is set.
aria-requiredSet to "true" if required is set.