Examples

Phone number

The unmasked digits come from onValueChange.

Preview

Format: (555) 123-4567

Stored value: —

Example.tsx
import { MaskedInput, Stack, Text } from '@reactloom/ui';
import { useState } from 'react';

export default function Example() {
  const [digits, setDigits] = useState('');
  return (
    <Stack gap="2" style={{ maxInlineSize: 320 }}>
      <MaskedInput label="Mobile number" description="Format: (555) 123-4567" mask="(999) 999-9999" autoComplete="tel-national" onValueChange={(raw) => setDigits(raw)} />
      <Text size="sm" tone="muted">
        Stored value: {digits || '—'}
      </Text>
    </Stack>
  );
}

Mask tokens

9 digit, a letter, * letter or digit; other characters are inserted for the user.

Preview

MM/YY

Six digits, for example 12-34-56

Three letters, then four letters or digits

Example.tsx
import { MaskedInput, Stack } from '@reactloom/ui';

// `9` digit, `a` letter, `*` letter or digit, `\` makes the next character literal.
export default function Example() {
  return (
    <Stack gap="4" style={{ maxInlineSize: 320 }}>
      <MaskedInput label="Card expiry" description="MM/YY" mask="99/99" autoComplete="cc-exp" />
      <MaskedInput label="Sort code" description="Six digits, for example 12-34-56" mask="99-99-99" />
      <MaskedInput label="Product code" description="Three letters, then four letters or digits" mask="aaa-****" />
    </Stack>
  );
}

API reference

MaskedInput props
PropTypeDefault
maskrequired
Pattern: 9 digit, a letter, * letter or digit, \\ escapes the next character.
string—
value / defaultValue
Unmasked characters.
string—
onValueChange
Called with the unmasked and the displayed value.
(raw, masked) => void—
label
Visible label.
ReactNode—
description · error
Help text and error, linked with aria-describedby.
ReactNode—
hideLabel · required · disabled · size
As on Input.
—
…Input props
Every Input prop; the displayed (masked) text is what a form submits.
—

Customization

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

Renders Input, so its hooks apply too.

Slot class names

Add classes to inner parts with classNames (className is shorthand for root): root, label, description, control, input, section, error.

CSS variables

VariableDefault
--pl-input-radiusvar(--pl-radius-md

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-disabled]present when on
[data-invalid]present when on
[data-radius]none · sm · md · lg · full
[data-readonly]present when on
[data-size]sm · md · lg

Theme tokens it reads

--pl-color-bg-subtle --pl-color-bg-surface --pl-color-border-default --pl-color-border-focus --pl-color-border-input --pl-color-danger-border --pl-color-fg-default --pl-color-fg-disabled --pl-color-fg-muted --pl-color-fg-subtle --pl-control-height-lg --pl-control-height-md --pl-control-height-sm --pl-focus-ring-color --pl-focus-ring-width --pl-font-size-lg --pl-font-size-md --pl-font-size-sm --pl-radius-full --pl-radius-lg --pl-radius-md --pl-radius-none --pl-radius-sm --pl-shadow-xs

Accessibility

  • It is a native text input: paste, autofill, undo and screen readers work as usual.
  • Literals are typed for the user; Backspace after a literal removes the character before it.
  • Digit-only masks set inputmode="numeric" for a number keyboard on phones.
  • Say the expected format in the label or description — a mask alone is not an instruction.
Keyboard interactions
KeyAction
TypeCharacters fill the next slots; others are ignored
BackspaceDeletes the character before the caret, across literals

Usage guidelines

Do

  • Use for fixed-length formats people already know.
  • Store the unmasked value and format it again for display.

Don’t

  • Don’t mask free-form values such as names, international phone numbers or addresses.