PIN input
ProOne 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
PinInput 57 props
The number of boxes, 3–12.
The characters it accepts. Letter types are upper-cased.
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.Shows a dot instead of each character, for PINs.
Lets the phone offer the code from an SMS or email (
autocomplete="one-time-code"). Turn it off for PINs and other codes.Splits the boxes into groups, e.g.
[3, 3]for123–456. They must add up tolength.What goes between groups.
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-*inclassNameto limit it.The text field style of each box:
outlinedorfilled.Box size:
sm40×48px,md48×56px,lg56×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-smallkeeps the text field token's corner (--md-comp-<variant>-text-field-container-shape).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.The code (controlled).
The starting code (uncontrolled).
Helper text below the boxes. Replaced visually by the error message when invalid.
Marks the code invalid: the boxes turn
errorand the row shakes once.Marks the input required: an asterisk after the label, and form validation.
Dims the boxes and ignores input.
Shows the code without letting it change.
Ref to the root element.
Ref to the input that holds the code.
The label above the boxes. Required unless
aria-labeloraria-labelledbyis given.
Events
Called with the cleaned code whenever it changes.
Called once when the last box is filled, by typing, paste or autofill.
Text
Defines a string value that labels the current element.
One of
label,aria-labeloraria-labelledbyis required.Identifies the element (or elements) that labels the current element.
One of
label,aria-labeloraria-labelledbyis required.
Classes for the root; they win over the defaults via
cn().Classes for each part.
The root (the same element as
className).The label above the boxes.
The wrapper holding the boxes and the input that covers them, in one grid cell.
The row of boxes (and separators).
Each box.
Each separator between groups.
The supporting text below the boxes.
The error message below the boxes.
Inline styles for the root.
An enumerated attribute that defines what action label or icon to preset for the enter key on virtual keyboards. See MDN.
Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.
A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if
validationBehavior="native". For realtime validation, use theinvalidprop instead.An error message for the field.
Whether the element should receive focus on render.
Handler that is called when the element receives focus.
Handler that is called when the element loses focus.
Handler that is called when the element's focus status changes.
Handler that is called when a key is pressed.
Handler that is called when a key is released.
Identifies the element (or elements) that describes the object.
Identifies the element (or elements) that provide a detailed, extended description for the object.
The element's unique identifier. See MDN.
Describes the type of autocomplete functionality the input should provide if any. See MDN.
An attribute that takes as its value a space-separated string that describes what, if any, type of autocomplete functionality the input should provide. See MDN.
An enumerated attribute that defines whether the element may be checked for spelling errors. See MDN.
The name of the input element, used when submitting an HTML form. See MDN.
The
<form>element to associate the input with. The value of this attribute must be the id of a<form>in the same document. See MDN.Handler that is called when the user copies text. See MDN.
Handler that is called when the user cuts text. See MDN.
Handler that is called when the user pastes text. See MDN.
Handler that is called when a text composition system starts a new text composition session. See MDN.
Handler that is called when a text composition system completes or cancels the current text composition session. See MDN.
Handler that is called when a new character is received in the current text composition session. See MDN.
Handler that is called when text in the input is selected. See MDN.
Handler that is called when the input value is about to be modified. See MDN.
Handler that is called when the input value is modified. See MDN.
Identifies the element that provides an error message for the object.
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.
| Item | Status | Details |
|---|---|---|
| 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. |
Variants: outlined and filled
BuiltVariant · Variants
Sizes: small, medium and large
BuiltConfiguration · Variants
Groups, a separator and a custom pattern
BuiltConfiguration · Groups
Masked
BuiltConfiguration · Pin
Invalid, required, read-only and disabled
BuiltConfiguration · States, Verification
Density, 56 to 44px (
Builtdensity)Configuration · Density
A verification code that submits itself
BuiltUse case · Verification
Built on the M3 text field
ExtensionEach 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
outlinedboxes have anoutlineborder that turnson-surfaceon hover and 2pxprimaryin the active box;filledboxes have asurface-container-highestcontainer and an active indicator. Errors useerror, 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 markeddata-tokens="wm-pin-input". cornertakes 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-cornervariable 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.
| Variable | Default | Paints |
|---|---|---|
--wm-pin-input-container-color | var(--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-shape | var(--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-color | var(--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-color | var(--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-color | var(--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-color | var(--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-color | var(--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-color | var(--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-color | var(--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-width | 48pxVaries with size. | Each box’s width (40 / 48 / 56px by size); larger text makes it wider. |
--wm-pin-input-box-height | calc(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-gap | 8pxVaries with size. | Between boxes (6 / 8 / 8px by size). |
--wm-pin-input-separator-width | 16pxVaries with size. | The separator between groups (12 / 16 / 16px by size). |