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.

Purpose

A phone field takes a phone number with its country: people pick their country (or a pasted or autofilled +… number picks it), type the number in their country's usual format, and the app gets one international E.164 value such as +447911123456. It is not an M3 component: it comes from @windmorph/react-pro, and its number is the library's Text field.

The phone rules come from libphonenumber-js (Google's phone data), loaded only on pages that use the field. Country names come from the browser in the page's language, so no names ship with the library. Servers can check a value the same way with phoneProblem.

Behaviour

  • Both fields are one group, named by the label. Each country reads as its name and its dialling code as shown ("United Kingdom, +44"), so the country field's name contains the code people see.
  • id and the attributes that name or describe the number (aria-labelledby, aria-describedby, aria-details, aria-errormessage) go to the number's input, so a <label for> or an error summary's link reaches it, as do the attributes that describe it as a widget (aria-controls, aria-haspopup, aria-autocomplete, aria-activedescendant, aria-expanded, aria-required, aria-invalid, aria-readonly). The other aria-* attributes, data-*, title, lang and pointer events go to the group, as on the core's fields.
  • density (or the theme's, through a provider or ThemeScope) takes 4px a step off both fields and the country list's rows, from 56px at 0 to 44px at -3, as the core's fields do.
  • The field is 20rem wide: 320px at the default text size and at least 320px, so it grows with larger text and the number's label is never cut short at 200%.
  • readOnly makes the number read-only and keeps the country field enabled: it shows its country but doesn't open.
  • An invalid number shows the core's error icon once, on the number; the country field turns its own off, so it keeps its width.

When not to use

For a number whose country never varies and needs no checking, a Text field with type="tel" is enough.

See also

  • Text field: Filled or outlined text input with a floating label, icons, affixes, counter, error icon and a text area.
  • PIN input: One box per character for verification codes, PINs and vouchers, with paste and one-time-code autofill. Not an M3 component (@windmorph/react-pro).