# Phone input

Collect an exact phone value with explicit country context, optional extension and consumer-owned paste parsing.

Access: pro. Category: Forms. Kind: composite.

## When to use

- Use it when a page needs collect an exact phone value with explicit country context, optional extension and consumer-owned paste parsing.
- 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 phone 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 Phone input

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

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

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/phone-input.css";
import{TidalPhoneInput}from"./components/ui/phone-input";
export default()=><div className="tidal-scope"><TidalPhoneInput countries={[{code:"value",label:"Demo",dialCode:"value"}]} label={"Demo"} value={{country:"value",number:"value"}}/></div>;
```

## Structured props

- `TidalPhoneInput.countries: ReadonlyArray<TidalPhoneCountry>`: Required countries value accepted by this exported component.
- `TidalPhoneInput.label: ReactNode`: Required label value accepted by this exported component.
- `TidalPhoneInput.value: TidalPhoneValue`: Required value value accepted by this exported component.
- `TidalPhoneInput.countryLabel?: ReactNode` (default "Country or region"): Optional country label value accepted by this exported component.
- `TidalPhoneInput.countryName?: string | undefined` (default "phone-country"): Optional country name value accepted by this exported component.
- `TidalPhoneInput.countrySelectProps?: NativeCountryProps | undefined`: Optional country select props value accepted by this exported component.
- `TidalPhoneInput.countrySelectRef?: Ref<HTMLSelectElement> | undefined`: Optional country select ref value accepted by this exported component.
- `TidalPhoneInput.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalPhoneInput.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalPhoneInput.error?: ReactNode`: Optional error value accepted by this exported component.
- `TidalPhoneInput.extensionInputProps?: NativeInputProps | undefined`: Optional extension input props value accepted by this exported component.
- `TidalPhoneInput.extensionInputRef?: Ref<HTMLInputElement> | undefined`: Optional extension input ref value accepted by this exported component.
- `TidalPhoneInput.extensionLabel?: ReactNode` (default "Extension"): Optional extension label value accepted by this exported component.
- `TidalPhoneInput.extensionName?: string | undefined` (default "phone-extension"): Optional extension name value accepted by this exported component.
- `TidalPhoneInput.form?: string | undefined`: Optional form value accepted by this exported component.
- `TidalPhoneInput.labels?: Partial<{ dialCode: string; configurationError: ReactNode; unavailableCountry: string; }> | undefined` (default {}): Optional labels value accepted by this exported component.
- `TidalPhoneInput.numberInputProps?: NativeInputProps | undefined`: Optional number input props value accepted by this exported component.
- `TidalPhoneInput.numberLabel?: ReactNode` (default "Phone number"): Optional number label value accepted by this exported component.
- `TidalPhoneInput.numberName?: string | undefined` (default "phone-number"): Optional number name value accepted by this exported component.
- `TidalPhoneInput.onValueChange?: ((next: TidalPhoneValue, field: "country" | "number" | "extension", event: TidalPhoneChangeEvent) => void) | undefined`: Callback invoked when the value change interaction is proposed.
- `TidalPhoneInput.parsePaste?: ((request: TidalPhonePasteRequest) => TidalPhoneValue | null) | undefined`: Optional consumer parser used only for paste. Returning null rejects the paste.
- `TidalPhoneInput.readOnly?: boolean | undefined` (default false): Optional read only value accepted by this exported component.
- `TidalPhoneInput.required?: boolean | undefined` (default false): Optional required value accepted by this exported component.
- `TidalPhoneInput.rootClassName?: string | undefined` (default ""): Optional root class name value accepted by this exported component.
- `TidalPhoneInput.rootProps?: Omit<HTMLAttributes<HTMLDivElement>, "className" | "aria-disabled" | "children" | "dangerouslySetInnerHTML"> | undefined`: Optional root props value accepted by this exported component.
- `TidalPhoneInput.rootRef?: Ref<HTMLDivElement> | undefined`: Optional root ref value accepted by this exported component.
- `TidalPhoneInput.showExtension?: boolean | undefined` (default true): Optional show extension value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/phone-input.tsx) | [Manifest](https://tidalui.com/examples/phone-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
"use client";

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

import { useId, useState, type ReactNode } from "react";

import { TidalPhoneInput, type TidalPhonePasteRequest, type TidalPhoneValue } from "./components/ui/phone-input";

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



const tidalExampleStyles = ".tidal-scope .phone-input-demo,\n.tidal-scope .phone-input-demo * {\n  box-sizing: border-box;\n}\n\n.tidal-scope .phone-input-demo {\n  container: phone-input-demo / inline-size;\n  display: grid;\n  width: min(100%, 680px);\n  min-width: 0;\n  gap: 16px;\n  color: var(--t-ink);\n}\n\n.tidal-scope .phone-input-demo-actions {\n  display: flex;\n  flex-wrap: wrap;\n  gap: 9px;\n}\n\n.tidal-scope .phone-input-demo-actions button {\n  display: inline-flex;\n  min-width: 128px;\n  min-height: 44px;\n  align-items: center;\n  justify-content: center;\n  padding: 9px 14px;\n  border: 1px solid var(--t-border);\n  border-radius: var(--t-radius-control);\n  background: var(--t-surface);\n  color: var(--t-ink);\n  font: inherit;\n  font-size: 12px;\n  font-weight: 700;\n  cursor: pointer;\n  transition:\n    color 140ms,\n    background-color 140ms,\n    border-color 140ms,\n    transform 140ms var(--t-ease-out);\n}\n\n.tidal-scope .phone-input-demo-actions button[type=\"submit\"] {\n  border-color: var(--t-ink);\n  background: var(--t-ink);\n  color: var(--t-surface);\n}\n\n.tidal-scope .phone-input-demo-actions button:hover {\n  border-color: var(--t-ink);\n}\n\n.tidal-scope .phone-input-demo-actions button[type=\"reset\"]:hover {\n  background: var(--t-ink);\n  color: var(--t-surface);\n}\n\n.tidal-scope .phone-input-demo-actions button:active {\n  transform: scale(0.98);\n}\n\n.tidal-scope .phone-input-demo-actions button:focus-visible {\n  outline: 2px solid var(--t-accent);\n  outline-offset: 3px;\n}\n\n.tidal-scope .phone-input-demo-status,\n.tidal-scope .phone-input-demo-note {\n  min-width: 0;\n  margin: 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.5;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .phone-input-demo-note {\n  padding-block-start: 10px;\n  border-block-start: 1px solid var(--t-border);\n}\n\n@container phone-input-demo (max-width: 360px) {\n  .tidal-scope .phone-input-demo-actions {\n    display: grid;\n    grid-template-columns: minmax(0, 1fr);\n  }\n\n  .tidal-scope .phone-input-demo-actions button {\n    width: 100%;\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .tidal-scope .phone-input-demo-actions button {\n    transition: none;\n  }\n\n  .tidal-scope .phone-input-demo-actions button:active {\n    transform: none;\n  }\n}";

const COUNTRIES = [
  { code: "US", label: "United States", dialCode: "+1" },
  { code: "CA", label: "Canada", dialCode: "+1" },
  { code: "GB", label: "United Kingdom", dialCode: "+44" },
  { code: "AU", label: "Australia", dialCode: "+61" },
] as const;

const INITIAL_VALUE: TidalPhoneValue = {
  country: "US",
  number: "202 555 0147",
  extension: "204",
};

function parseSamplePaste({
  text,
  value,
  countries,
}: TidalPhonePasteRequest): TidalPhoneValue | null {
  const trimmed = text.trim().replace(/^tel:/i, "");
  if (!trimmed) return null;
  const extensionMatch = trimmed.match(/(?:ext\.?|x)\s*([0-9]+)\s*$/i);
  const withoutExtension = extensionMatch
    ? trimmed.slice(0, extensionMatch.index).trim()
    : trimmed;
  const currentCountry = countries.find(
    (country) => country.code === value.country,
  );
  const prefixedCountry =
    (currentCountry && withoutExtension.startsWith(currentCountry.dialCode)
      ? currentCountry
      : countries
          .filter((candidate) =>
            withoutExtension.startsWith(candidate.dialCode),
          )
          .sort((a, b) => b.dialCode.length - a.dialCode.length)[0]) ??
    undefined;
  const country = prefixedCountry ?? currentCountry;
  const number = prefixedCountry
    ? withoutExtension.slice(prefixedCountry.dialCode.length).trim()
    : withoutExtension;
  return {
    country: country?.code ?? value.country,
    number,
    extension: extensionMatch?.[1] ?? value.extension,
  };
}

export function PhoneInputDemo() {
  const generatedId = useId().replace(/:/g, "");
  const [value, setValue] = useState<TidalPhoneValue>(INITIAL_VALUE);
  const [error, setError] = useState<ReactNode>(null);
  const [status, setStatus] = useState(
    "Edit the sample number or paste a number with an extension.",
  );

  return (
    <form
      id={generatedId}
      className="phone-input-demo"
      aria-label="Phone input preview"
      onSubmit={(event) => {
        event.preventDefault();
        const formData = new FormData(event.currentTarget);
        setError(null);
        setStatus(
          `Prepared ${String(formData.get("contact-country"))} ${String(formData.get("contact-phone"))}${formData.get("contact-extension") ? ` extension ${String(formData.get("contact-extension"))}` : ""} locally.`,
        );
      }}
      onReset={(event) => {
        if (event.defaultPrevented) return;
        setValue(INITIAL_VALUE);
        setError(null);
        setStatus("Sample phone details reset.");
      }}
    >
      <TidalPhoneInput
        label="Contact phone"
        description="Select a country and enter its local phone number."
        error={error}
        countries={COUNTRIES}
        value={value}
        onValueChange={(next, field) => {
          setValue(next);
          setError(null);
          setStatus(
            field === "country"
              ? "Country context updated."
              : "Sample phone details updated.",
          );
        }}
        parsePaste={parseSamplePaste}
        form={generatedId}
        countryName="contact-country"
        numberName="contact-phone"
        extensionName="contact-extension"
        required
        numberInputProps={{
          placeholder: "202 555 0147",
          onInvalid: (event: import("react").InvalidEvent<HTMLInputElement>) => {
            event.preventDefault();
            setError("Enter a phone number for this local sample.");
            setStatus("Check the phone number.");
            event.currentTarget.focus({ preventScroll: true });
          },
        }}
      />

      <div className="phone-input-demo-actions">
        <button type="submit">Prepare sample</button>
        <button type="reset">Reset</button>
      </div>
      <p className="phone-input-demo-status" role="status" aria-live="polite">
        {status}
      </p>
      <p className="phone-input-demo-note">
        Sample data. Paste handling uses this preview’s local adapter.
      </p>
    </form>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <PhoneInputDemo />
    </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."}

label, countries with unique nonblank code/label/dialCode values, controlled country/number/extension value and optional onValueChange are the core contract. Native country select, tel number and optional extension fields preserve exact consumer values and external form/name participation. parsePaste is an optional consumer adapter used only after the native paste handler; returning null rejects the paste. The component does not infer countries, format numbers, validate international numbering plans or claim a universally valid phone number. Native input/select props and refs, disabled/readOnly/required, linked description/error, unknown-country recovery, 44px controls, 16px text, RTL, forced colors and reduced motion are supported. Root aria-disabled is component-owned so it cannot contradict the native controls. Consumers own parsing, validation, serialization, persistence and requests.
