PhoneInput

A phone field with a country picker. Digits take the country's grouping as you type, a pasted +44 number switches the country, and you always get E.164 back. Inputs.

Open playground
10 digits for United Kingdom

About

PhoneInput is a React component in the Inputs category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { PhoneInput } from "@ashutoshswamy/smoui" and set label, value, onChange among its 5 props.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { PhoneInput } from "@ashutoshswamy/smoui";

<PhoneInput label="Mobile number" defaultCountry="GB" onChange={(e164, valid) => save(e164, valid)} />

Props 5

label

Label above the field.

string
value / defaultValue

E.164 number such as "+14155550132", or an empty string.

string
onChange

Gets the E.164 string and whether every digit is in.

(value: string, valid: boolean) => void
defaultCountry

ISO code shown while the field is empty.

stringdefault "US"
countries

Replace the built-in list. Each has code, name, dial and a mask where # is a digit.

PhoneCountry[]