Skip to content

PIN input

Pro

One box per character for verification codes, PINs and vouchers, with paste and one-time-code autofill. Not an M3 component (@windmorph/react-pro).

import { PinInput } from '@windmorph/react-pro';

Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.

Props

By name or description, across the 57 props below

PinInput 57 props

  • lengthtype numberdefault 6

    The number of boxes, 3–12.

  • typetype "numeric" | "alphanumeric" | "alphabetic"default "numeric"

    The characters it accepts. Letter types are upper-cased.

  • patterntype RegExp

    A one-character test that replaces type's own, e.g. /[2-9A-HJ-NP-Z]/ for codes without the easily confused 0, O, 1 and I.

  • masktype boolean

    Shows a dot instead of each character, for PINs.

  • otptype booleandefault true

    Lets the phone offer the code from an SMS or email (autocomplete="one-time-code"). Turn it off for PINs and other codes.

  • groupstype readonly number[]

    Splits the boxes into groups, e.g. [3, 3] for 123–456. They must add up to length.

  • separatortype ReactNodedefault an en dash

    What goes between groups.

  • fullWidthtype booleandefault false

    The field spans its container's width: the boxes share it equally (never narrower than 1em, about a digit) and separators keep their width. Set a max-w-* in className to limit it.

  • varianttype "outlined" | "filled"default "outlined"

    The text field style of each box: outlined or filled.

  • sizetype "sm" | "md" | "lg"default "md"

    Box size: sm 40×48px, md 48×56px, lg 56×64px (at density 0).

  • cornertype "none" | "extra-small" | "small" | "medium" | "large" | "large-increased" | "extra-large" | "extra-large-increased" | "extra-extra-large" | "full"default "extra-small" (the text field's)

    A corner from the M3 shape scale. extra-small keeps the text field token's corner (--md-comp-<variant>-text-field-container-shape).

  • densitytype 0 | -1 | -2 | -3

    Web density, 0 to -3: each step takes 4px off the boxes' height, as the core's fields. Left out, it follows the theme's or the nearest ThemeScope's.

  • valuetype string

    The code (controlled).

  • defaultValuetype string

    The starting code (uncontrolled).

  • supportingTexttype ReactNode

    Helper text below the boxes. Replaced visually by the error message when invalid.

  • invalidtype boolean

    Marks the code invalid: the boxes turn error and the row shakes once.

  • requiredtype boolean

    Marks the input required: an asterisk after the label, and form validation.

  • disabledtype boolean

    Dims the boxes and ignores input.

  • readOnlytype boolean

    Shows the code without letting it change.

  • reftype Ref<HTMLDivElement>

    Ref to the root element.

  • inputReftype Ref<HTMLInputElement>

    Ref to the input that holds the code.

  • labeltype ReactNode

    The label above the boxes. Required unless aria-label or aria-labelledby is given.

Events

  • onChangetype ((value: string) => void)

    Called with the cleaned code whenever it changes.

  • onCompletetype ((value: string) => void)

    Called once when the last box is filled, by typing, paste or autofill.

Text

  • aria-labeltype string

    Defines a string value that labels the current element.

    One of label, aria-label or aria-labelledby is required.

  • aria-labelledbytype string

    Identifies the element (or elements) that labels the current element.

    One of label, aria-label or aria-labelledby is required.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Spec status

Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.

  • Variants: outlined and filled

    Built

    Variant · Variants

  • Sizes: small, medium and large

    Built

    Configuration · Variants

  • Corners from the M3 shape scale

    Built

    Configuration · Corners, Pin

  • Character sets: numeric, alphabetic and alphanumeric

    Built

    Configuration · Corners, Groups

  • Groups, a separator and a custom pattern

    Built

    Configuration · Groups

  • Masked

    Built

    Configuration · Pin

  • Invalid, required, read-only and disabled

    Built

    Configuration · States, Verification

  • Density, 56 to 44px (density)

    Built

    Configuration · Density

  • A verification code that submits itself

    Built

    Use case · Verification

  • Built on the M3 text field

    Extension

    Each box reads the --wm-pin-input-* tokens, whose defaults are the text field’s outlined or filled tokens, so a text field theme restyles it too. One real input sits over the boxes, so autofill, paste and screen readers see a single field.

M3 Expressive specs

Sizes
sm, md, lg
Shape
rounded-corner-extra-small
Variants
outlined, filled

Theming & tokens

  • outlined boxes have an outline border that turns on-surface on hover and 2px primary in the active box; filled boxes have a surface-container-highest container and an active indicator. Errors use error, so every theme, mode and contrast level follows.
  • The boxes read the --wm-pin-input-* tokens below, whose defaults are the core's text field tokens: a --md-comp-outlined-text-field-* or --md-comp-filled-text-field-* override restyles the boxes as it does a Text field and a Phone field. Set them on the input (className) or any ancestor; the root is marked data-tokens="wm-pin-input".
  • corner takes any step of the M3 shape scale; the default is the text field's extra-small. For a corner of your own, set --wm-pin-input-container-shape (the old --wm-pin-corner variable is gone).
  • New characters pop in on the fast spatial spring and fade in on the fast effects spring, and border changes use the fast effects spring, from the active motion scheme. Under reduced motion the pop is skipped but the fade stays.
PIN input tokens
VariableDefaultPaints
--wm-pin-input-container-colorvar(--md-comp-outlined-text-field-container-color, transparent)Varies with variant.Each box’s container (the filled text field’s `surface-container-highest` when `filled`).
--wm-pin-input-container-shapevar(--md-comp-outlined-text-field-container-shape, var(--md-sys-shape-corner-extra-small))Varies with variant and corner.Each box’s corners (only the top ones when `filled`). The `corner` prop sets the default.
--wm-pin-input-outline-colorvar(--md-comp-outlined-text-field-outline-color, var(--md-sys-color-outline))Varies with variant.Each box’s 1px outline, or its active indicator when `filled`.
--wm-pin-input-hover-outline-colorvar(--md-comp-outlined-text-field-hover-outline-color, var(--md-sys-color-on-surface))Varies with variant.The outline or indicator under the pointer.
--wm-pin-input-focus-outline-colorvar(--md-comp-outlined-text-field-focus-outline-color, var(--md-sys-color-primary))Varies with variant.The active box’s 2px outline or indicator.
--wm-pin-input-input-text-colorvar(--md-comp-outlined-text-field-input-text-color, var(--md-sys-color-on-surface))Varies with variant.The characters and the mask dots.
--wm-pin-input-caret-colorvar(--md-comp-outlined-text-field-caret-color, var(--md-sys-color-primary))Varies with variant.The caret in the active, empty box.
--wm-pin-input-label-text-colorvar(--md-comp-outlined-text-field-label-text-color, var(--md-sys-color-on-surface-variant))Varies with variant.The label above the boxes.
--wm-pin-input-focus-label-text-colorvar(--md-comp-outlined-text-field-focus-label-text-color, var(--md-sys-color-primary))Varies with variant.The label while the input has focus.
--wm-pin-input-box-width48pxVaries with size.Each box’s width (40 / 48 / 56px by size); larger text makes it wider.
--wm-pin-input-box-heightcalc(56px + var(--md-sys-density, 0) * 4px)Varies with size.Each box’s minimum height (48 / 56 / 64px by size), 4px less a density step; larger text makes it taller.
--wm-pin-input-gap8pxVaries with size.Between boxes (6 / 8 / 8px by size).
--wm-pin-input-separator-width16pxVaries with size.The separator between groups (12 / 16 / 16px by size).