PinInput

Maintainer:
amje
GitHub
size
type
length
placeholder
note
validationState
errorMessage
disabled
otp
mask
import {PinInput} from '@gravity-ui/uikit';

PinInput is a group of inputs to enter sequence of numeric or alphanumeric values quickly. Its most common use case is entering OTP or confirmation codes received through text messages (SMS), emails, or authenticator apps.

Each input collects one character at a time. When a value is accepted, the focus is moved to the next input, until all fields are filled.

Type

By default, the inputs only accept numeric values. To allow alphanumeric values, set the type property to "alphanumeric":

<PinInput type="alphanumeric" />

Size

This component comes in four sizes: s, m, l, and xl. The default size is m.

<PinInput size="s" />
<PinInput size="m" />
<PinInput size="l" />
<PinInput size="xl" />

State

If you do not want the user to interact with the component, set the disabled property:

<PinInput disabled />

To show an invalid state of the component, use the validationState property with the "invalid" value. Optionally, you can set an error message text with the errorMessage property:

Incorrect PIN
<PinInput validationState="invalid" errorMessage="Incorrect PIN" />

Placeholder

By default, there is no placeholder for inputs. You can set it with the placeholder property:

<PinInput placeholder="😎" />

Mask

If you need to mask entered values, use the mask property. It is similar to the <input type="password"/> behavior.

<PinInput mask />

OTP

If you want the browser to suggest one-time codes from the outer context (e.g., SMS) set the otp property.

API

  • focus(): void: Sets focus to the current active input.

CSS API

NameDescription
--g-pin-input-item-widthSets the width of each input, unless responsive is true.
--g-pin-input-item-gapSets a gap between inputs.

Properties

NameDescriptionTypeDefault
apiRefRef to the API.React.RefObject
aria-describedbyaria-describedby HTML attributestring
aria-labelaria-label HTML attributestring
aria-labelledbyaria-labelledby HTML attributestring
autoFocusEnables or disables focusing on the first input on the initial render.boolean
classNameclass HTML attributestring
defaultValueInitial value for an uncontrolled component.string[]
disabledToggles the disabled stateboolean
errorMessageError text placed under the bottom-start corner that shares space with the note container. Only visible when validationState is set to "invalid".React.ReactNode
idid HTML attribute prefix for inputs. The resulting ID will also contain the "-${index}" part.string
lengthNumber of input fields.number4
maskWhen set to true, the input values will be masked as the password field.boolean
namename HTML attribute for input.string
formThe associate form of the underlying input element.string
noteAn element placed under the bottom-end corner that shares space with the error container.React.ReactNode
onUpdateCallback fired when any of inputs changes.(value: string[]) => void
onUpdateCompleteCallback fired when any of inputs changes and all of them are filled.(value: string[]) => void
otpWhen set to true, adds autocomplete="one-time-code" to inputs.boolean
placeholderPlaceholder for inputsstring
qadata-qa HTML attribute used for testing purposes.string
responsiveParent's width distributed evenly between inputs.boolean
sizeInput field size."s" "m" "l" "xl""m"
stylestyle HTML attributeReact.CSSProperties
typeDetermines which input value types are allowed."numeric" "alphanumeric""numeric"
validationStateValidation state that affects the component appearance."invalid"
valueCurrent value for the controlled component.string[]
onFocusCallback fired when the component receives focus.(event: React.FocusEvent<Element>) => void
onBlurCallback fired when the component loses focus.(event: React.FocusEvent<Element>) => void