# Masked input

Enter structured identifiers through a native text field while forms receive the exact raw token value.

Access: pro. Category: Forms. Kind: primitive.

## When to use

- Use it when a product interface needs enter structured identifiers through a native text field while forms receive the exact raw token value.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose form-field instead when a labeled email field with validation and help text is the actual interface need, rather than masked input.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Masked input

```sh
npx shadcn@latest add @tidal-pro/masked-input
```

Stylesheets: `components/ui/tidal.css`, `components/ui/masked-input.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/masked-input.css";
import{TidalMaskedInput}from"./components/ui/masked-input";
export default()=><div className="tidal-scope"><TidalMaskedInput label={"Demo"} mask={"value"} onValueChange={() => {}} value={"value"}/></div>;
```

## Structured props

- `TidalMaskedInput.label: ReactNode`: Required label value accepted by this exported component.
- `TidalMaskedInput.mask: string`: A bounded mask. Defaults: # digit, A ASCII letter, * ASCII letter or digit.
- `TidalMaskedInput.onValueChange: (value: string, event: ChangeEvent<HTMLInputElement> | KeyboardEvent<HTMLInputElement> | CompositionEvent<HTMLInputElement>) => void`: Callback invoked when the value change interaction is proposed.
- `TidalMaskedInput.value: string`: Controlled raw token characters, without mask literals.
- `TidalMaskedInput.aria-disabled?: Booleanish | undefined`: Accessible disabled supplied by the consumer.
- `TidalMaskedInput.aria-invalid?: boolean | "true" | "false" | "grammar" | "spelling" | undefined`: Accessible invalid supplied by the consumer.
- `TidalMaskedInput.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalMaskedInput.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalMaskedInput.error?: ReactNode`: Optional error value accepted by this exported component.
- `TidalMaskedInput.hiddenInputRef?: Ref<HTMLInputElement> | undefined`: Optional hidden input ref value accepted by this exported component.
- `TidalMaskedInput.labels?: TidalMaskedInputLabels | undefined` (default {}): Optional labels value accepted by this exported component.
- `TidalMaskedInput.name?: string | undefined`: Optional name value accepted by this exported component.
- `TidalMaskedInput.onChange?: ChangeEventHandler<HTMLInputElement, HTMLInputElement> | undefined`: Callback invoked when the change interaction is proposed.
- `TidalMaskedInput.onCompositionEnd?: CompositionEventHandler<HTMLInputElement> | undefined`: Callback invoked when the composition end interaction is proposed.
- `TidalMaskedInput.onCompositionStart?: CompositionEventHandler<HTMLInputElement> | undefined`: Callback invoked when the composition start interaction is proposed.
- `TidalMaskedInput.onInput?: InputEventHandler<HTMLInputElement> | undefined`: Callback invoked when the input interaction is proposed.
- `TidalMaskedInput.onKeyDown?: KeyboardEventHandler<HTMLInputElement> | undefined`: Callback invoked when the key down interaction is proposed.
- `TidalMaskedInput.readOnly?: boolean | undefined` (default false): Optional read only value accepted by this exported component.
- `TidalMaskedInput.required?: boolean | undefined` (default false): Optional required value accepted by this exported component.
- `TidalMaskedInput.rootClassName?: string | undefined` (default ""): Optional root class name value accepted by this exported component.
- `TidalMaskedInput.tokens?: ReadonlyArray<TidalMaskToken> | undefined` (default DEFAULT_TOKENS): Optional tokens value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/masked-input.tsx) | [Manifest](https://tidalui.com/examples/masked-input.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
import "./components/ui/tidal.css";

import "./components/ui/masked-input.css";

import { useRef, useState, type FormEvent } from "react";

import { TidalMaskedInput } from "./components/ui/masked-input";



const tidalExampleStyles = ".tidal-scope .masked-input-demo {\n  display: grid;\n  width: 100%;\n  max-width: 560px;\n  min-width: 0;\n  gap: 22px;\n  margin: 0 auto;\n}\n\n.tidal-scope .masked-input-demo-actions {\n  display: flex;\n  min-width: 0;\n  flex-wrap: wrap;\n  gap: 8px;\n}\n\n.tidal-scope .masked-input-demo-actions button {\n  min-width: 44px;\n  min-height: 44px;\n  padding: 9px 14px;\n  color: var(--t-ink);\n  background: var(--t-surface);\n  border: 1px solid var(--t-border);\n  border-radius: var(--t-radius-control);\n  font: inherit;\n  font-size: 12px;\n  font-weight: 700;\n  line-height: 1.25;\n  overflow-wrap: anywhere;\n  cursor: pointer;\n  transition:\n    color 160ms var(--t-ease-out),\n    background 160ms var(--t-ease-out),\n    border-color 160ms var(--t-ease-out),\n    transform 140ms var(--t-ease-out);\n}\n\n.tidal-scope .masked-input-demo-actions button:last-child {\n  margin-inline-start: auto;\n  color: var(--t-surface);\n  background: var(--t-ink);\n  border-color: var(--t-ink);\n}\n\n.tidal-scope .masked-input-demo-actions button:focus-visible {\n  outline: 2px solid var(--t-accent);\n  outline-offset: 3px;\n}\n\n.tidal-scope .masked-input-demo-status,\n.tidal-scope .masked-input-demo-note {\n  margin: 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.55;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .masked-input-demo-status {\n  min-height: 18px;\n  color: var(--t-ink);\n  font-weight: 650;\n}\n\n@media (hover: hover) and (pointer: fine) {\n  .tidal-scope .masked-input-demo-actions button:hover {\n    color: var(--t-surface);\n    background: var(--t-ink);\n    border-color: var(--t-ink);\n  }\n\n  .tidal-scope .masked-input-demo-actions button:active {\n    transform: scale(0.975);\n  }\n}\n\n@media (max-width: 390px) {\n  .tidal-scope .masked-input-demo {\n    gap: 18px;\n  }\n\n  .tidal-scope .masked-input-demo-actions {\n    display: grid;\n    grid-template-columns: repeat(2, minmax(0, 1fr));\n  }\n\n  .tidal-scope .masked-input-demo-actions button:last-child {\n    grid-column: 1 / -1;\n    margin-inline-start: 0;\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .tidal-scope .masked-input-demo-actions button {\n    transition: none;\n    transform: none;\n  }\n}";

const INITIAL_PHONE = "442079460123";

const INITIAL_REFERENCE = "UI2026WAVE";

export function MaskedInputDemo() {
  const [phone, setPhone] = useState(INITIAL_PHONE);
  const [reference, setReference] = useState(INITIAL_REFERENCE);
  const [status, setStatus] = useState(
    "The visible format and raw form values are ready to inspect.",
  );
  const phoneInput = useRef<HTMLInputElement>(null);

  function submit(event: FormEvent<HTMLFormElement>) {
    event.preventDefault();
    const data = new FormData(event.currentTarget);
    setStatus(
      `Local form values: phone ${String(data.get("phone"))}; reference ${String(data.get("reference"))}.`,
    );
  }

  return (
    <form
      className="masked-input-demo"
      onSubmit={submit}
      onReset={() => {
        setPhone("");
        setReference("");
        setStatus("Local fields cleared.");
        queueMicrotask(() =>
          phoneInput.current?.focus({ preventScroll: true }),
        );
      }}
    >
      <TidalMaskedInput
        ref={phoneInput}
        label="Sample phone number"
        mask="+## ## #### ####"
        value={phone}
        onValueChange={(next) => {
          setPhone(next);
          setStatus("Sample phone value changed locally.");
        }}
        name="phone"
        inputMode="numeric"
        autoComplete="tel"
        placeholder="+44 20 7946 0123"
        description="This example format is supplied by the demo. Consumers choose the mask that fits their data."
        required
      />

      <TidalMaskedInput
        label="Project reference"
        mask="AA-####-****"
        value={reference}
        onValueChange={(next) => {
          setReference(next);
          setStatus("Project reference changed locally.");
        }}
        name="reference"
        autoComplete="off"
        placeholder="UI-2026-WAVE"
        description="Letters are normalized to uppercase; the raw form value omits separators."
        required
      />

      <div className="masked-input-demo-actions">
        <button
          type="button"
          onClick={() => {
            setPhone(INITIAL_PHONE);
            setReference(INITIAL_REFERENCE);
            setStatus("Sample values restored.");
            phoneInput.current?.focus({ preventScroll: true });
          }}
        >
          Fill sample
        </button>
        <button type="reset">Clear</button>
        <button type="submit">Read form values</button>
      </div>

      <output className="masked-input-demo-status">{status}</output>
      <p className="masked-input-demo-note">
        Local sample only. The component formats input and prepares exact native
        form values; it makes no request and stores nothing.
      </p>
    </form>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <MaskedInputDemo />
    </div>
  );
}

```

## Gotchas

- Keep field state, validation results, submission, and persistence in the host form workflow.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Controlled raw value and caller-owned onValueChange; bounded mask grammar with default digit, ASCII letter and alphanumeric tokens or consumer-supplied single-character tokens; escaped literals and sparse compatible-slot assignment preserve later values when an earlier token is deleted; optional case transforms apply only when the result remains one valid character; semantic label, description, progress and string validity messages; exact hidden native form mirror; native input, form, autocomplete, inputMode and event props; caller-first preventable input/change/key/composition handlers; selection-aware Backspace/Delete, paste and IME completion; required/incomplete validity, disabled/readOnly, visible and hidden refs, RTL, forced colors and reduced motion. The component formats only the supplied mask and performs no request, storage, country inference or identifier validation beyond token matching.
