Components
Phone Input
Country-aware phone number field with flag selector and national number formatting.
Overview
PhoneInput is the shared phone number field for forms that need country-code selection and national number formatting.
It composes:
- a searchable country
Selectwith flag and calling code - a national number
InputwithinputMode="tel"
The component manages display formatting internally and commits the serialized phone value on blur via onBlur.
Basic Usage
import { PhoneInput } from '@fsai/shared-ui';
<PhoneInput
label="Phone number"
value={phone}
onBlur={setPhone}
/>With Error State
<PhoneInput
label="Mobile"
value={phone}
onBlur={setPhone}
error={errors.phone}
fullWidth
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Optional field label. |
value | string | null | — | Stored phone value (E.164 or serialized format from SDK). |
onBlur | (value: string | null) => void | — | Called when the field blurs with the serialized phone value. |
error | string | — | External validation error message. |
disabled | boolean | — | Disables both the country select and number input. |
fullWidth | boolean | — | Makes the field container full width. |
defaultCountry | PhoneCountryCode | SDK default | Country used when parsing an empty or ambiguous value. |
placeholder | string | '(555) 123-4567' | Placeholder for the national number input. |
className | string | — | Additional classes on the root container. |
Value Handling
PhoneInput uses @fsai/sdk phone utilities:
resolvePhoneForDisplayparses the stored value into country + national number for displayformatNationalPhoneInputformats the national number as the user typesserializePhoneForStoragevalidates and serializes on blur
The field commits on blur, not on every keystroke. This matches typical form validation patterns where the parent owns the stored value.
Local validation errors (such as invalid number format) appear alongside external error props.
Important Conventions
- Use
onBluras the value commit callback, notonChange. - The country selector is searchable and shows flag, country name, and calling code in the dropdown.
- The country selector column is fixed width (
7rem); the number input fills the remaining space. - Prefer passing already-serialized values from the backend rather than raw national numbers.
Guidelines
- Do use
PhoneInputfor user-facing phone fields in forms - Do handle validation errors via the
errorprop from your form layer - Do persist the serialized value returned by
onBlur - Don't use a plain
Inputfor phone numbers when country selection matters - Don't expect live
onChangecallbacks — the value commits on blur