UI

Phone

An international phone field with a morphing country picker, live national formatting, typing guide, paste and autofill detection, and E.164 output.

import { PhoneInput } from '@uthereal/ui/phone-input'

Phone input playground

Used for two-factor verification codes.
Loading interactive preview…

Overview

PhoneInput renders a labelled international telephone field. Activating the country button grows it into a searchable country list inside the same surface, while the national number formats live beside a faint typing guide showing the rest of the expected pattern.

Typing + inside the number input opens the picker seeded for calling-code search. Pasting or browser-autofilling an international number (+44 7400 123456 or 0044 7400 123456) selects the matching country automatically, strips redundant trunk digits, and emits canonical E.164 (+447400123456).

CapabilityBehavior
Output valueCanonical E.164 (+14155550132, or "" when empty); hidden <input type="hidden"> submits E.164 when name is set
Country table49 built-in countries with national formats, trunk prefixes (0, 1), and shared-code disambiguation (+1 US/CA)
Typing guideFaint continuation of the active country's realistic example number, aligned character-for-character with typed digits
Paste & autofillParses + and 00 numbers into country and national digits, drops redundant trunk zeros, and trims extra calling codes
ValidationShows a live check icon when digit length matches a country pattern; optional post-blur error (validate) or host error

Use PhoneInput for phone numbers that need country selection, national formatting, and E.164 normalization. Use Text for free-form extensions, SIP URIs, or non-standard contact strings.

Usage

'use client'
import { useState } from 'react'
import { PhoneInput, type PhoneInputDetails } from '@uthereal/ui/phone-input'

export function ContactPhone() {
  const [phone, setPhone] = useState('')
  const [country, setCountry] = useState('US')

  function handleChange(next: string, _details: PhoneInputDetails) {
    setPhone(next)
  }

  return (
    <PhoneInput
      label="Mobile number"
      name="phone_e164"
      value={phone}
      onValueChange={handleChange}
      country={country}
      onCountryChange={setCountry}
      description="Used for two-factor verification codes."
    />
  )
}

Omit value and country for an uncontrolled field initialized from defaultValue and defaultCountry. When name is set, a hidden <input type="hidden"> submits the current E.164 string with native HTML forms unless the field is disabled.

Examples

Regional country pool

Pass countries to restrict the picker to accepted ISO 3166-1 alpha-2 codes and set defaultCountry to a code within that pool. Use preferredCountries to pin frequent choices under Suggested at the top of the list, or pass [] to display a single alphabetical list without group headings.

Restricted to European operating regions.

International formatting and validation

Set defaultValue to any E.164 number to initialize both the country and formatted national digits. Set validate={false} when your application owns validation and supplies error directly, or set readOnly to present a verified phone number that users can focus and copy without editing.

Valid United Kingdom number
This number could not be reached for SMS verification.
Contact support to change your verified number.
Valid United States number

API reference

These serializable arguments and defaults come directly from the component schema.

ArgumentType / defaultDescription
labelstringDefault: "Phone number"Visible label and accessible name. Name the information asked for, in sentence case.
hideLabelbooleanDefault: falseHide the label visually when the context already names the field. It is still announced.
descriptionstring—Supporting text below the field, announced with it. Use it for format hints and constraints.
errorstring—Validation message from your application. Setting it marks the field invalid; the message is linked to the field and announced politely.
requiredbooleanDefault: falseMarks the field as required for assistive technology and shows an indicator. Your application validates the value.
readOnlybooleanDefault: falseThe value can be focused, selected, and copied, but not edited. It is still submitted with a form.
disabledbooleanDefault: falseUnavailable and removed from the tab order. A disabled field is not submitted with a form.
namestring—Native form field name, submitted with the value in a form.
defaultValuestringDefault: ""Initial number in E.164 ("+14155550132"), or empty. Later argument edits do not reset an existing instance; use value and onValueChange to control it.
defaultCountrystringDefault: "US"Initial ISO country code (US by default), used until someone picks a country or enters an international number.
countriesstring[]Default: []ISO codes the picker offers, at most 49; an empty array offers every country.
preferredCountriesstring[]Default: ["US","CA","GB"]ISO codes pinned under "Suggested" at the top of the picker (US, CA, GB by default); at most 12.
validatebooleanDefault: trueShow a message after blur when the number is incomplete or too long for its country. On by default.
autoCompletestringDefault: "tel"HTML autocomplete token for the number input, "tel" by default.
labelsPhoneInputLabels—Reader-facing copy: the country button, the search field, the list headings, announcements, and the validation message.
variantoutline | soft | ghostDefault: "outline"Field surface: outline in forms, soft, or ghost inline.
sizesm | md | lgDefault: "md"Field height and text size.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themePhoneInputTheme—Color mode, accent, and semantic tokens. See Theming for all keys and defaults.
motionnone | subtle | expressiveDefault: "subtle"The surface morph, the gliding highlight and message copy. Reduced motion keeps short fades; none makes every change immediate.
motionOptionsPhoneInputMotionOptions—Fine tune the gliding highlight spring.
dirltr | rtl—Reading direction. Omit it to inherit the page direction.

React integration

PropPurpose
value, onValueChangeControlled E.164 string ("+14155550132", or ""). Callback receives (value, details).
country, onCountryChangeControlled ISO 3166-1 alpha-2 country code ("US") and selection callback.
refRef to the native <input type="tel"> element.
presetApplication defaults (such as defaultCountry, preferredCountries, labels), overridden locally
tokensCSS custom properties (--ui-*) applied after the typed theme on the field root.
className, styleApplied to the root field element, which carries the resolved tokens.
Native attributesForwarded to <input type="tel"> (onBlur, onFocus, onKeyDown, autoFocus, aria-*).

PhoneInputDetails provides { country, formatted, status, valid } on every change, where status is 'empty' | 'incomplete' | 'valid' | 'too-long'. Pure helpers (PHONE_COUNTRIES, parsePhoneNumber, formatPhoneNumber, formatNational, toE164, statusOf, countryOf, flagOf, lengthsOf) are also exported from @uthereal/ui/phone-input.

Keyboard & accessibility

KeyInteraction
+ (number input)Opens the country picker seeded with + for immediate calling-code search.
Backspace, Delete (number)Crossing a formatting separator ((, ), -, space) deletes the adjacent digit instead of stalling.
ArrowDown, ArrowUp (trigger)Opens the country picker and moves focus into the search combobox.
Character keys (trigger)Opens the country picker and seeds the search input with the typed character.
ArrowDown, ArrowUp (search)Moves the active option one row forward or backward and scrolls it into view.
PageDown, PageUp (search)Moves the active option by 8 rows.
Home, End (search, empty)Jumps to the first or last country option when the search query is empty; moves the caret when text exists.
Enter (search)Selects the active country, closes the picker, and focuses the number input.
Escape (search)Closes the picker without changing the country and returns focus to the country button.
Tab (search)Closes the picker and lets focus continue naturally to the number input.

The country button exposes aria-haspopup="listbox", aria-expanded, aria-controls, and an accessible name combining labels.countryLabel, the country name, and the calling code. When open, the button becomes inert and focus moves to the search <input role="combobox"> wired with aria-autocomplete="list" and aria-activedescendant targeting the active <div role="option">. Suggested and remaining countries render inside role="group" containers labelled by their headings.

Search match counts, empty-search notices, country changes from paste or autofill, and valid-number confirmations announce through a pre-mounted role="status" (aria-live="polite") region. In dir="rtl", the field shell, country trigger, and morphing panel mirror from inline-start while calling codes and the national number box stay dir="ltr" so digits, separators, and the typing guide never scramble. forced-colors: active preserves panel borders, internal dividers, active option Highlight/HighlightText contrast, disabled colors, and focus outlines.

Motion and theming

  • Morphing surface: width, height, and corner radius animate on a critically damped 0.42s physical spring when opening (and when calling-code length changes) and close quicker on a 0.26s critically damped spring so retargeting mid-flight preserves velocity.
  • Country layer and highlight: picking a country rolls the flag and calling code vertically in list order through a subtle blur; pointer moves glide the active-row highlight on motionOptions.indicator (0.42s critically damped by default), while keyboard moves and filtering jump it immediately.
  • Valid indicator and messages: completing a valid number springs the check icon in (0.26s, bounce 0.12), and hint or validation messages rise smoothly via the shared field message animation.
  • Reduced motion: prefers-reduced-motion: reduce jumps surface geometry, chevron rotation, and highlight position immediately while keeping 120ms opacity crossfades. motion="none" makes all updates immediate (0ms).

theme accepts the core and control token groups, plus borderStrong, borderSubtle, surfaceSunken, success, popupPadding, itemHeight, itemPaddingX, itemPaddingY, itemRadius, and four component tokens: panelMaxWidth (--ui-phone-input-panel-max-width), closedRadius (--ui-phone-input-closed-radius), openRadius (--ui-phone-input-open-radius), and listMaxHeight (--ui-phone-input-list-max-height). An optional UtherealProvider supplies application-wide defaults.

Composition

PhoneInput is a leaf component. Its E.164 phone number is host state at /fields/instance-<id>/value (initialized from defaultValue), and its ISO 3166-1 alpha-2 country code is host state at /fields/instance-<id>/country (initialized from defaultCountry). Stored E.164 values and valid country codes within the active countries pool survive configuration edits. See Building with agents.

{
  "type": "PhoneInput",
  "props": {
    "label": "Support phone",
    "defaultCountry": "GB",
    "preferredCountries": ["GB", "IE", "US"],
    "description": "Include your area code."
  },
  "children": []
}

On this page