Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Phone Input

ProNew

A phone field with a country in front. The number is grouped as you type in the country's own format, the caret stays put, and pasting an international number selects its country.

Installation

pnpm dlx shadcn@latest add @viewport/phone-input

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
valuestring

The number in international form, e.g. "+14155550142".

—
defaultValuestring""
onValueChange(value: string, detail: { country: string; complete: boolean }) => void

Called with the international number, and whether it has as many digits as the country expects.

—
defaultCountrystring

The ISO code of the country selected at first, e.g. "US".

"US"
size"sm" | "md" | "lg""md"

Accessibility

  • The country is a select named with the country and its code; typing a name jumps to it.
  • The field is a tel input with the right keyboard on phones and autocomplete.
  • Reports one international number, and submits it through a hidden input.
  • Takes aria-invalid and the ids a Field passes down.