Phone Input
ProNewA 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
| Prop | Type | Default |
|---|---|---|
| value | stringThe number in international form, e.g. "+14155550142". | — |
| defaultValue | string | "" |
| onValueChange | (value: string, detail: { country: string; complete: boolean }) => voidCalled with the international number, and whether it has as many digits as the country expects. | — |
| defaultCountry | stringThe 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.