Phone input

A country and a number, kept as one value. What the field reports is E.164 or nothing, never the text on screen, so what reaches an API is always dialable.

Reach for it

A phone number, where what is stored has to be dialable.

Not for

A reference that happens to be digits. This one refuses what is not a number.

Typing, pasting, and what comes out

The number is grouped the way the selected country writes it, and the value underneath stays E.164. A number typed with its dialling code moves the country button rather than contradicting it, so a pasted international number needs no correction. While what is typed is too short to be a real number the value is null, because half a phone number is not a phone number.

Type 0612345678, or paste a number that starts with its dialling code

Committed value: null

A stored number, split back into its two halves

The list is in the reader's language

Country names come from Intl.DisplayNames and the order from Intl.Collator, so the package ships neither a country list nor a translation of one. The flags are fetched after the field is on screen rather than with it: every flag in the world is 58kB gzipped and a full country list needs all of them, so their box is reserved and they paint a moment later without moving anything.

La liste est triée et nommée en français

API reference

PhoneInput

PropTypeDefaultDescription
locale*string-Names the countries and orders them. Required, not defaulted: a list sorted in the wrong language is a list nobody can scan.
defaultCountry*CountryCode-How a number typed without a dialling code is read. Required, because it cannot be guessed. A locale is a language, not a place: `en` is spoken in a dozen countries with a dozen prefixes, and picking one of them silently turns a British number into an American one.
countryLabel*string-Names the country button, e.g. "Country dialling code".
countrySearchPlaceholder*string-Placeholder in the country search box, e.g. "Search a country".
countryEmptyLabel*string-Shown when the search matches no country.
size'small' | 'medium' | 'large'medium
hasStartAdornmentbooleanfalseRoom for a marker or a button inside the control's own padding box. The padding belongs to the control, so it lives here. The marker's own geometry belongs to the marker, so it lives in adornment.ts. Four components each carried the whole table before, and the one in combobox.tsx said "mirroring SearchInput" in a comment, which is the note a copy leaves behind.
hasEndAdornment'true' | 'false' | 'double'false`double` is two markers at the end, a clear button beside a calendar button. Twice the room, so the value never runs under either of them.
valuestring | null-E.164, e.g. "+33612345678".
defaultValuestring | null-
onValueChange(value: string | null) => void-Fires with E.164, or null while what is typed is not yet a valid number in the selected country.

Also takes the standard attributes of a input, minus className, style, size, type, value, defaultValue, onChange and inputMode.