SwipeUI

Phone input

Local as-you-type phone formatting, a searchable country dropdown and validated E.164 output.

npx @swipeui/cli add phone-input
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When to use it

  • Collecting phone numbers for sign-up, delivery or two-factor setup.
  • International apps where people pick their country and see the number formatted as they type.
  • Storing numbers in the standard E.164 format, such as +14155552671.
  • Pasting a full international number and detecting the country.

When not to use it

  • Verifying that a number really exists; it only checks the numbering pattern is valid.
  • Free-form contact notes.
  • Choosing a country on its own. Use Combobox.

Installation

Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.

npx @swipeui/cli add phone-input
  • Adds components/swipeui/ui/phone-input.tsx and 15 shared helpers.
  • Installs libphonenumber-js, react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg, react-native-gesture-handler, react-native-safe-area-context. In Expo apps it uses npx expo install so versions match your SDK.

Usage

app/sign-up.tsx
import { PhoneInput } from '@/components/swipeui/ui/phone-input';

<PhoneInput label="Phone number" defaultCountry="US" onValueChange={setPhone} />;

Examples

Use the variant and appearance controls in the live specimen to compare the documented states. The application owns validation, operation results and persistence.

API reference

PhoneInputProps

PropTypeDefaultDescription
label?string—

Visible label, or inherit an enclosing Field.

helper?string—

Instructions under the field; an error or success message replaces it.

error?string—

Validation message: a destructive ring, an alert glyph, one shake and an error haptic.

success?string—

Confirmation under the field, such as "Username available", in the success colour.

status?FieldStatus'idle'

validating shows a spinner and reports busy; valid draws a check on. An error implies invalid.

required?booleanfalse

Required; "Required" is spoken, and requiredIndicator marks the label. The app owns validation.

requiredIndicator?FieldRequiredIndicator'asterisk'

How a required label is marked: a muted asterisk, the word, or nothing.

optionalIndicator?booleanfalse

Show a muted "Optional" after the label.

disabled?booleanfalse

Disable editing and accessory actions.

disabledStyle?FieldDisabledStyle'muted'

muted lightens the fill and text without opacity; dim lowers the field to 50%.

appearance?FieldAppearance'filled'

The surface: filled (a soft fill), outline (a hairline), underline or ghost (no fill until focused).

size?FieldSize'md'

Height: sm 36pt, md 44pt, lg 52pt.

shape?FieldShape'preset'

preset follows your preset's control radius; pill is a capsule.

labelPlacement?FieldLabelPlacement'above'

above, inset (small, inside at the top), floating (rests centred like a hint and rises on focus or once there's a value) or hidden (spoken only).

focusRing?FieldFocusRing'halo'

The focus indicator: a primary ring with a soft halo, the ring alone, or none.

messageMorph?FieldMessageMorph'fade'

How a changed message arrives: rises in, letter by letter, or at once.

reserveMessageSpace?booleanfalse

Keep one line of room under the field so forms don't move as messages appear.

displayValue?React.ReactNode—

Decorative rendering for an unfocused value; the native text remains the accessible/editable source.

suffix?React.ReactNode—

Accessible trailing accessory, drawn last.

leadingIcon?ButtonIcon—

A leading icon: a node, or a function given the state colour and size. It turns primary while focused.

trailingIcon?ButtonIcon—

A trailing icon: a node, or a function given the state colour and size.

clearable?booleanfalse

1.x switch: true means clearButton="always".

clearButton?TextFieldClearButton'never' (or 'always' with `clearable`)

When a "Clear text" button shows.

undoClear?booleantrue

After clearing, the button becomes "Undo clear" for a moment. Phones have no ⌘Z.

undoClearWindow?number4000

How long undo stays, in milliseconds.

counter?TextFieldCounterfalse

A rolling character counter under the field, using maxLength; amber near the limit, red at it.

tintCaret?booleantrue

Caret and selection in the primary colour.

iconTint?"focus" | "none"'focus'

The leading icon turns primary while focused (focus) or stays muted (none).

shakeOnError?booleantrue

Shake once for each new error. Reduce Motion keeps it still.

messages?Partial<FieldMessages>FIELD_MESSAGES (English)

Built-in strings, for translation.

nextRef?React.RefObject<_TextInputInstance | null>—

Ref focused when Return is pressed; otherwise a single-line field dismisses.

haptics?boolean | FieldHapticstrue (clear, error and limit)

All feedback, or each part: { clear, error, valid, limit, focus }.

motion?MotionOverridethe app feel

Ring, label and message motion.

className?string—

Classes on the outer field.

controlClassName?string—

Classes on the field surface.

inputClassName?string—

Classes on the editable text.

style?StyleProp<ViewStyle>—

Outer field style.

inputStyle?____TextStyleProp_Internal—

Native editable text style.

value?string—

E.164 text, or an empty string. Partial editing stays local.

defaultValue?string''

Initial E.164 text.

onValueChange?((value: string) => void)—

Reports a possible-length E.164 number, or '' while incomplete. Not carrier verification.

defaultCountry?CountryCode'US'

Country for national-number entry.

countries?readonly CountryCode[]all metadata countries

Countries offered in the picker.

showValidCheck?booleantrue

Show a success check when the national number is valid.

limitLength?booleantrue

Enforce country length limits (India: ten national digits).

locale?stringdevice locale

Country-name locale.

onCountryChange?((country: CountryCode) => void)—

Reports an explicit country selection or international-number inference.

Native view/input props not listed here pass through where the exported TypeScript type allows them.

Composition and behavior

  • A country button that opens a Sheet list, next to a phone Text field.
  • value is E.164 text; defaultCountry and countries limit choices.
  • onCountryChange reports selection or detection.

Phone input settings

The flag and calling code open an anchored country dropdown. Search by country name or +calling code. All metadata countries are available by default, including on Hermes without Intl.DisplayNames. The national-number area has country length limits and a green check for a valid numbering pattern. India is capped at ten digits. Invalid drafts show an error on blur. This does not verify number ownership.

PropDoesDefault
countriesRestrict offered countriesall metadata countries
showValidCheckDraw the valid-number checktrue
limitLengthEnforce country maximum lengthtrue
localeCountry-name locale, with English fallbackdevice

Behavior and gestures

  • Tap the country button to open a searchable dropdown of countries with calling codes.
  • Type the national number and it formats as you go, for that country.
  • Paste an international number and the country is detected once.
  • The value is reported only when the numbering pattern is valid; until then it's an empty string.

Accessibility

  • The country button reads "Choose country or region, United States" and reports expanded state.
  • Each country in the dropdown reads its name and calling code, and the selected one is marked.
  • Country names follow the device language unless you set locale.
  • The phone keypad is used for entry.

Motion

  • Uses the press and overlay motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • The country dropdown opens with the overlay role.
  • Reduce Motion fades it instead.

Performance

  • Formatting runs locally with libphonenumber-js; nothing is sent anywhere.

Notes for AI

  • Store the E.164 value; set defaultCountry to the user's likely region.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items