Skip to content
Protocore Design Systemv1.6.9

/// Inputs

MaskInput

An Input that formats typing against a fixed mask (phone, card, date), owning the raw characters and displaying the masked string.

import { MaskInput } from "@protocore/pds";
View as Markdown

Basics

Pass a mask string — # is a digit, A a letter, * alphanumeric, and every other character is a literal shown in place. The component inserts literals as you type.

Raw + masked value

onValueChange(raw, masked) reports both the significant characters and their formatted rendering. Store raw; show masked. The control is controllable by its raw value.

raw: · masked:

Formats

The same component covers card numbers, dates, and license plates — it is just a different mask.

When to use it

Use MaskInput for fixed-shape values that read better with separators — phone numbers, card numbers, dates, postal codes. For free numeric entry with steppers use NumberInput; for a one-time code use PinInput / OTPInput; for calendar-backed dates use DateInput. A mask formats input — it does not guarantee the value is real; validate on submit.

Usage

Do

  • Persist the `raw` value; render the `masked` one.
  • Give it an `aria-label` or wrap it in a `Field`.
  • Match the mask to the real format your backend expects.

Don't

  • Don't treat a full mask as validation — a well-formed phone number can still be wrong.
  • Don't use a mask for open-ended text — it drops non-matching characters.
  • Don't mask secret one-time codes — use PinInput/OTPInput.

Accessibility

  • Renders a standard text input, so it inherits the Input focus ring and `aria-invalid`.
  • `inputMode` is inferred (`numeric` for digit-only masks) to surface the right mobile keypad.
  • Non-matching characters are ignored rather than silently accepted, keeping the display honest.

MaskInput props

PropTypeDefaultDescription
classNamestring
defaultValuestringInitial raw value when uncontrolled.
invalidbooleanMark the field invalid — danger border plus `aria-invalid`.
mask *stringThe format mask — `#` digit, `A` letter, `*` alphanumeric; other chars are literals.
onValueChange((raw: string, masked: string) => void)Fires with the next raw value and its masked rendering.
sizeenummdControl height: `sm` (32) · `md` (36, default) · `lg` (40).
styleCSSProperties
valuestringControlled raw value (significant characters only). Pair with `onValueChange`.

Related

  • InputThe base single-line text control — a sunken field with optional leading and trailing adornment slots.
  • NumberInputNumeric field with a mono tabular value and a hairline stepper column — clamps to min/max and steps with the arrow keys.
  • PinInputAlias of OTPInput — segmented single-character fields for one-time codes and PINs.
  • DateInputSegmented day/month/year field with spinbutton segments — the keyboard-first, type-to-fill alternative to the calendar.