Skip to content

Phone field

Pro

A phone number with a searchable country picker; formats as typed and reports E.164. Not an M3 component (@windmorph/react-pro).

import { PhoneField } from '@windmorph/react-pro';

Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.

Props

By name or description, across the 29 props below

PhoneField 29 props

  • varianttype "filled" | "outlined"default "filled"

    The text field style of both parts: filled or outlined. Filled by default, as the core TextField and Select beside it are, so a form matches without a prop.

  • densitytype 0 | -1 | -2 | -3

    Web density, 0 to -3: each step takes 4px off both fields (56px at 0, 44px at -3) and off the country list's rows. Left out, it follows the theme's or the nearest ThemeScope's.

  • valuetype string

    The number in E.164 (+447911123456), or '' (controlled).

  • defaultValuetype string

    The starting number in E.164 (uncontrolled); it also picks the starting country.

  • countrytype "AC" | "AD" | "AE" | "AF" | "AG" | "AI" | "AL" | "AM" | "AO" | "AR" | "AS" | "AT"

    The chosen country (ISO 3166-1 alpha-2); one dialling code can cover several.

  • defaultCountrytype "AC" | "AD" | "AE" | "AF" | "AG" | "AI" | "AL" | "AM" | "AO" | "AR" | "AS" | "AT"

    The country to start on, e.g. the visitor's. Else the first priority country.

  • priorityCountriestype readonly CountryCode[]

    Listed first, in this order, e.g. an app's main markets.

  • renderFlagtype ((country: CountryCode) => ReactNode)

    A flag (or any icon) for a country, shown in the country field and the list. None by default.

  • localetype stringdefault the React Aria locale

    Locale for country names.

  • supportingTexttype ReactNode

    Helper text below the number. Replaced visually by the error when invalid.

  • invalidtype boolean

    Marks the number invalid. Without it, the field checks the number itself when it loses focus and shows errorMessage (or labels.invalid) for one that isn't valid.

  • errorMessagetype ReactNodedefault labels.invalid

    The error shown while invalid.

  • requiredtype boolean

    Marks the number required (an asterisk after the label, and form validation).

  • disabledtype boolean

    Disables both fields.

  • readOnlytype boolean

    Shows the number and country without letting them change.

  • nametype string

    Submits the E.164 value under this name.

  • autoFocustype boolean

    Focuses the number when the field mounts.

  • idtype string

    The number's <input> id (as on the core's fields), so a <label for> or an error summary's #id link reaches it.

  • reftype Ref<HTMLDivElement>

    Ref to the root element (the group).

  • inputReftype Ref<HTMLInputElement>

    Ref to the number's input.

  • labeltype string

    The number field's floating label, which also names the country field. Required unless aria-label or aria-labelledby is given.

Events

  • onChangetype ((value: string) => void)

    Called with the number in E.164, possibly incomplete while typing, or ''.

  • onCountryChangetype ((country: CountryCode) => void)

    Called when the country changes: chosen from the list, or picked by a +… number.

Text

  • labelstype Partial<PhoneFieldLabels>

    The words it shows and announces, merged over the English defaults. A LabelsProvider sets them for the whole app.

  • aria-labeltype string

    Names the number for screen readers when there's no visible label, e.g. "Phone number".

  • aria-labelledbytype string

    Identifies the element (or elements) that labels the current element.

    One of label, aria-label or aria-labelledby is required.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Spec status

Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.

  • Variants: filled (default) and outlined

    Built

    Variant · Variants

  • Priority countries and a starting country

    Built

    Configuration · Signup

  • Invalid number

    Built

    Configuration · Variants

  • Flags

    Built

    Configuration · Flags

  • Required, read-only and disabled

    Built

    Configuration · States

  • Country names in another language (locale)

    Built

    Configuration · States

  • Density, 56 to 44px (density)

    Built

    Configuration · Density

  • A phone number at sign-up

    Built

    Use case · Signup

  • Built on the M3 text field and select

    Extension

    The number is a TextField, and the country a searchable Select that opens as the M3 menu on medium and larger windows and as a bottom sheet on compact ones.

M3 Expressive specs

Shape
rounded-corner-extra-small
Variants
outlined, filled

Theming

  • The phone field has no values of its own to override: its parts take the core's Text field, Select, search and menu tokens, so a theme for those reaches it. Its root is marked data-tokens="wm-phone-field".
  • Like the core's fields, it is filled by default, or outlined. The country field is a Select, so it has the Text field's tokens in both variants: the outline or filled container, 2px primary when focused or open, and error when the number is invalid.
  • The search is the M3 search bar's field at 48px (M3's minimum touch target, so it doesn't dominate the 44px rows), with full corners, surface-container-high, and the focus ring for keyboard focus only.
  • The list is the one Select and Autocomplete use: the M3 menu's surface-container-low panel at elevation 2, with the chosen country in tertiary-container with a check, and state layers for hover and keyboard focus.
  • classNames reaches every part: the root group; the country field's country root, countryContainer and countryValue; the list's picker surface, pickerSheet (phones), pickerSearch, pickerOption and pickerHeading; and the number's number root, numberContainer, label, input (the real <input>), supportingText and errorText.