Phone Input

View as Markdown

A phone number with its country's flag and calling code. Type it as written at home or with its code; it's handed over as +447700900123.

We'll text a code to it when you sign in.

Saved as —

When to use

A phone number with its country's flag and calling code. Type it as written at home or with its code; it's handed over as +447700900123. Use Input instead when the number is free text you won't call or text, so no country or format matters.

Usage

import { FormField } from "./ui/uicontext/components/FormControls.ts"import { PhoneInput } from "./ui/uicontext/components/PhoneInput.ts"
export const Phone = <M>(h: Html.H<M>, onChange: (value: string, valid: boolean) => M) =>	FormField(h, { id: "phone", label: "Phone" }, (field) =>		PhoneInput(h, { props: { field, country: "US" }, onEmit: { RequestedChange: ({ value, valid }) => onChange(value, valid) } }))

Examples

A few countries, a saved number

countries sets which countries are offered and in what order. locale sets the language of their names.

Only for delivery questions.

API reference

Props

PhoneInput props
NameTypeDefaultDescription
fieldFieldAttrs—The attributes a Form Field hands its control: id, description and error wiring.
labelstring—The field's name when there's no Form Field: "Mobile number".
valuestring—The number to start with, as "+447700900123".
countrystring"US"The country picked when the value doesn't say; "US" by default.
countriesstring[]phoneCountriesThe countries offered, by code, in order; all of phoneCountries by default.
localestring—The language country names are written in; the browser's by default.
disabledboolean——

Events

PhoneInput events
EventPayloadDescription
RequestedChange{ value: string; country: string; valid: boolean }The number changed: as "+447700900123" ("" when empty), its country, and whether it has the right digits.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/phone-input

Source