PhoneInput <pm-phone-input>
Phone input: a country picker and a telephone field that give one international number.
Sizes
Set with the size attribute; controls keep touch-sized targets on phones.
size="xs"size="sm"size="md"size="lg"size="xl"States
Each state is one attribute.
DisabledRead-onlyRequiredErrorOverview
value is the number in international form (+14155550123), which is what the form submits; the reader types the national number as they know it, with spaces or dashes if they like. Pasting a number that starts with + sets the country. Country names come from the browser in the page's language. It checks the length (8 to 15 digits with the country code); it does not know each country's numbering plan, so verify the number on your server or by sending a code.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
country | string | — | Selected country as a two-letter code, e.g. GB. Default: the region of the page's or the browser's language, else US. |
countries | string | — | Offer only these countries, in this order: countries="US,CA,MX". |
placeholder | string | — | Hint text shown while empty (not a replacement for label). |
country-labelprop: countryLabel | string | — | Accessible name of the country picker (default "Country"). |
autocomplete | string | — | Autofill hint of the number field (default tel-national). |
name | string | — | Form field name: the value is submitted under it. |
value | string | — | Current value (submitted with the form). |
label | string | — | Visible label (required for accessibility; use hide-label to visually hide it). |
hint | string | — | Help text under the field, linked to it for screen readers. |
error | string | — | Custom error message. Setting it marks the control invalid. |
size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | — | Control size. |
required | boolean | false | The form cannot be submitted until this has a value. |
disabled | boolean | false | Not interactive and not submitted. |
readonly | boolean | false | Focusable and submitted, but not editable. |
hide-labelprop: hideLabel | boolean | false | Hide the label visually; it stays the accessible name. |
Also accepts the contextual attributes tone, surface, radius, density, motion, elevation. They are inherited from ancestors' data-* attributes.
Events
| Event | React / Svelte prop | Description |
|---|---|---|
pm-input | onPmInput | While typing. detail.value (international), detail.country and detail.national. |
pm-change | onPmChange | The number or the country was committed. Same detail. |
CSS parts
| Part | Description |
|---|---|
::part(control) | The native telephone input. |
::part(country) | The country picker. |
Methods
checkValidity(), reportValidity(), validate(), focus()