Phone Input

Lightweight phone field with a searchable country dial code list and square SVG flags from the SonoJS flags CDN (emoji fallback if the image fails). Ships a local countries.json - no phone validation library. Control height matches SonoJS h-[46px].

Basic

Country dial picker with CDN SVG flags plus a national number field.

Loading…

Installation

CLI
npx @sonojs/ui@latest add phone-input
Also needs
npx @sonojs/ui@latest add input-group popover
npm i lucide-react

Usage

phone-input.tsx
import { PhoneInput } from "@/components/phone-input"

export function Example() {
  return <PhoneInput defaultCountry="US" placeholder="Phone number" />
}

Props

PropTypeDefaultDescription
defaultCountrystring"US"Initial ISO2 country code when uncontrolled.
countrystring-Controlled ISO2 country code.
onCountryChange(country: PhoneCountry) => void-Fires when the selected country changes.
valuestring-Controlled national number (without dial code).
defaultValuestring""Initial national number when uncontrolled.
onChange(value: string) => void-Fires when the national number changes.
disabledbooleanfalseDisables the country picker and input.
placeholderstring"Phone number"Input placeholder.
flagCdnBasestringSonoJS flags jsDelivrCDN base for flag SVGs (no trailing slash). Default: `https://sonojs.github.io/SonoJS-flags`.
showFlagbooleantrueWhen `false`, hides flag images and shows dial codes only.
classNamestring-Merge Tailwind classes on the input group root.