Skip to content
v2.5.0
English
Русский
Documentation

PinField

PinField is a compound component for fixed-length codes such as OTPs and PINs.

Root Props

PropTypeDefault
valuestring—
Controlled code.
defaultValuestring''
Initial code for uncontrolled usage. Defaults to ''.
onChangeValue(value: string) => void—
Called with the code when it changes.
disabledboolean—
Disables the input field, making it non-interactive. Also applies a visual disabled style.
placeholderstring—
Placeholder character shown when the field is empty.
sizePinFieldSize'md'
Visual size of the pin input. Affects dimensions and font size.
errorboolean—
Shows the field in an error state.
refRef<HTMLDivElement>—
Ref to the root element.
maskArray<RegExp | string> | RegExp—
Characters the field accepts: a RegExp for the whole value, or an array with a RegExp or a fixed character per position. Defaults to digits.
maxLengthnumber4
Number of characters in the code. Defaults to 4.

Also accepts all <div> attributes.

Child Parts

  • PinFieldInput: backing input for actual value and focus handling.
  • PinFieldSlot: visible slot for one index.
  • PinFieldSeparator: visual divider between groups.

PinFieldSlot

PropTypeDefault
indexrequirednumber—
The zero-based index of the slot within the PinField sequence.

Also accepts all <div> attributes.

PinFieldSeparator

PropTypeDefault
sizePinFieldSize—
Controls the visual size of the separator. Aligns with the size of the surrounding PinField elements.

Also accepts all <div> attributes.

PinFieldInput

PropTypeDefault
refRef<HTMLInputElement>—
Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

Also accepts all <input> attributes.

Types

  • PinFieldProps
  • PinFieldInputProps
  • PinFieldSlotProps
  • PinFieldSeparatorProps
  • PinFieldSize

State Model

  • The root tracks value, active slot index, and selection-all state.
  • PinFieldInput is the real editable control.
  • Slots derive content, active state, placeholder state, and disabled/error styling from context.
  • The root takes value, defaultValue and onChangeValue; PinFieldInput reads the value from the root and still fires its own onChange and onInput. A form reset restores defaultValue unless the field is controlled.
  • disabled and maxLength are set only on PinField, so the input and the slots always agree.
  • The root placeholder is also the placeholder of the input.