Masked Input

A text input with built-in mask formatting for phone numbers, dates, and custom patterns. Includes an optional date-picker popover.

Demo

Installation

pnpm dlx shadcn@latest add @turbopills-ui/masked-input

Usage

tsx
1import { MaskedInput } from "@/components/turbopills/ui/masked-input"
tsx
1export function PhoneField() {
2  const [value, setValue] = React.useState("")
3 
4  return (
5    <MaskedInput
6      title="Phone number"
7      preset="tel"
8      value={value}
9      onChange={setValue}
10    />
11  )
12}

Examples

Date Preset

The "date" preset provides MM/DD/YYYY formatting and a calendar popover for quick date selection:

Custom Mask

Use preset="custom" with your own mask and replacement pattern:

Error State

Pass errorMessage to display validation feedback:

Small Size

A compact variant for inline or toolbar usage:

Props

MaskedInputProps

PropTypeDefaultDescription
titlestringOptional heading displayed above the input.
hintstringOptional hint text shown below the title.
size"md" | "sm""md"Controls the height and text size of the input.
suffixReact.ReactNodeContent rendered to the right of the input value. Ignored when preset="date" (calendar icon is shown instead).
errorMessagestringWhen set, shows a red border and displays the error text below the input.
disabledbooleanfalseDisables the input.
valuestringControlled input value.
onChange(value: string) => voidCallback fired when the value changes.
preset"tel" | "date" | "custom""custom"Built-in mask preset. "tel" formats as (___) ___-____, "date" formats as MM/DD/YYYY with a calendar popover. Use "custom" with your own mask and replacement.
maskstringMask pattern string (e.g. "AAA-0000"). Overrides preset mask when provided.
replacementRecord<string, RegExp>Map of mask characters to allowed input patterns. Overrides preset replacement.
separatebooleanWhen true, each mask segment is treated independently. Automatically enabled for "tel" preset.
showMaskbooleantrueWhether to display the mask placeholder while the input is empty or partially filled.
calendarCaptionLayout"label" | "dropdown" | "dropdown-months" | "dropdown-years""dropdown"Caption layout for the date-picker calendar (only applies when preset="date").
placeholderstringPlaceholder text. Defaults to the preset's placeholder when not provided.
wrapperClassNamestringAdditional class names for the outer wrapper element.
classNamestringAdditional class names for the <input> element itself.

The component also accepts all standard React.InputHTMLAttributes<HTMLInputElement> props (except size, onChange, and value, which are replaced by the custom props above).