Web · Components
CountryField
CountrySelect with its label, description and error message.
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Import
CountrySelect with its label, description and error message. For address forms; the value is the ISO code ("TR").
Examples
PhoneInput with a country code, label, description and error message. Submitted in the form as E.164 (+905321234567); for a number whose length doesn't fit the country, the error shows below the field.
Examples
Country flag. On systems that can't render flag emoji (Windows) it shows the country code as a small badge. Decorative; screen readers don't read it.
Examples
Country picker: with a flag, the country's name in the user's language and search. Takes all Select props; the value is an ISO 3166-1 alpha-2 code ("TR"). Country names come from the browser's own translations; no extra data is downloaded. Search looks at the name, code and dial code (+49); the long list is drawn with virtual scrolling and opens from the bottom on mobile.
Use CountryField in address forms and PhoneInput for phones.
Examples
Phone input with a country code: a flag + dial code picker on the left, and the number grouped by the country's format on the right. Submitted in the form under name in E.164 format (+905321234567); no parsing needed on the server.
- A leading
0is dropped even if typed (0532…→+90532…). - Typing or pasting
+49 …or0049 …changes the country automatically. - If the length doesn't fit the country's rule the field is invalid; the message appears below the field.
- The phone keyboard opens on mobile; browser autofill works.
For labeled use see PhoneField.
Examples
countryFlag
functionFlag emoji: countryFlag("TR") → "🇹🇷".
countryName
functionThe country's name in the locale language; the code itself without a translation.
getCountries
functionAll countries, sorted by name in the locale language.
Examples
dialCodeOf
functionDialing code of a country ("TR" → "90"); undefined when unknown.
countryFromDialCode
functionFinds the country from the dialing code at the start of an international number (longest match). preferred is the country to prefer among those sharing a code (e.g. +1 US/Canada).
phonePlaceholder
functionNational number placeholder of a country ("(532) 123 45 67").
formatNationalNumber
functionGroups a national number with the country's pattern: "5321234567" → "(532) 123 45 67".
nationalDigits
functionReduces a national number typed by the user to digits; the leading 0 is dropped.
parsePhone
functionParses a phone number. When it starts with + or 00, the country comes from the dialing code; otherwise it counts as a national number of defaultCountry.
Examples
isValidNational
functionDoes the national number's length follow the country's rule?
isValidPhone
functionIs the number valid (a length check; it does not verify the number is in use)? Works with a schema on the server: z.string().refine((v) => isValidPhone(v), "Invalid number").
formatPhone
functionTurns an E.164 number into a readable form: "+905321234567" → "+90 (532) 123 45 67".
CountryCode
typeISO 3166-1 alpha-2 country code ("TR", "DE"…).
Country
interfaceInfo of a country.
| Name | Type | Description |
|---|---|---|
code | CountryCode | ISO 3166-1 alpha-2 code ("TR"). |
name | string | Name in the selected language ("Türkiye"). |
dialCode | string | International dialing code without + ("90"). |
flag | string | Flag emoji ("🇹🇷"). |
ParsedPhone
interfaceResult of parsePhone.
| Name | Type | Description |
|---|---|---|
country | CountryCode | Country code. |
dialCode | string | Calling code ("90"). |
national | string | National number, digits only ("5321234567"). |
e164 | string | E.164 form ("+905321234567"); "" when the number is empty. |
valid | boolean | Does the length follow the country's rule? |
Props of the CountryField component.
Extends: FieldOwnProps & Omit<Omit<SingleSelectProps, "items" | "loadItems" | "multiple">, "className">
| Name | Type | Default | Description |
|---|---|---|---|
countries? | readonly CountryCode[] | Only these countries are listed (e.g. ["TR", "DE", "NL"]). | |
priority? | readonly CountryCode[] | Countries shown in a separate group at the top of the list (e.g. ["TR"]). | |
locale? | string | {@link UIProvider} `locale | Language of country names. |
showDialCode? | boolean | false | Shows the dial code (+90) below the name. |
PhoneFieldProps
typeProps of the PhoneField component.
Extends: FieldOwnProps & Omit<Omit<ComponentProps<"input">, "value" | "defaultValue" | "type" | "onChange" | "size" | "prefix">, "className">
| Name | Type | Default | Description |
|---|---|---|---|
value? | string | Number in controlled use (E.164, e.g. "+905321234567"). | |
defaultValue? | string | Initial number in uncontrolled use (E.164 or national). | |
onValueChange? | (value: string, phone: ParsedPhone) => void | Called with the E.164 value and the parse result when the number changes. | |
defaultCountry? | CountryCode | "TR" | Country selected while the number is empty. |
onCountryChange? | (country: CountryCode) => void | Called when the country changes. | |
countries? | readonly CountryCode[] | Only these countries can be selected. | |
priority? | readonly CountryCode[] | [defaultCountry] | Countries shown at the top of the list. |
locale? | string | {@link UIProvider} `locale | Language of country names. |
countryName? | string | The selected country code is also submitted in the form under this name (e.g. "phoneCountry"). The number is always submitted as E.164 under name. | |
validate? | boolean | true | A number that doesn't fit the country's length rule makes the field invalid ("Enter a valid phone number"). |
variant? | FieldVariant | CustomVariant<"field"> | Appearance. See FieldVariant. | |
effect? | EffectProp | Effect or effects of the field box (e.g. "glow", ["lift", "beam"]). The accent color is the focus color (--ui-field-focus). Defaults to UIProvider appearance.defaults.field.effect. See BuiltinEffect. |
CountryFlagProps
interfaceProps of the CountryFlag component.
| Name | Type | Description |
|---|---|---|
code | CountryCode | ISO 3166-1 alpha-2 code ("TR"). |
className? | string | Extra classes. |
CountrySelectProps
interfaceProps of the CountrySelect component.
Extends: Omit<SingleSelectProps, "items" | "loadItems" | "multiple">
| Name | Type | Default | Description |
|---|---|---|---|
countries? | readonly CountryCode[] | Only these countries are listed (e.g. ["TR", "DE", "NL"]). | |
priority? | readonly CountryCode[] | Countries shown in a separate group at the top of the list (e.g. ["TR"]). | |
locale? | string | {@link UIProvider} `locale | Language of country names. |
showDialCode? | boolean | false | Shows the dial code (+90) below the name. |
PhoneInputProps
interfaceProps of the PhoneInput component.
Extends: Omit<ComponentProps<"input">, "value" | "defaultValue" | "type" | "onChange" | "size" | "prefix">
| Name | Type | Default | Description |
|---|---|---|---|
value? | string | Number in controlled use (E.164, e.g. "+905321234567"). | |
defaultValue? | string | Initial number in uncontrolled use (E.164 or national). | |
onValueChange? | (value: string, phone: ParsedPhone) => void | Called with the E.164 value and the parse result when the number changes. | |
defaultCountry? | CountryCode | "TR" | Country selected while the number is empty. |
onCountryChange? | (country: CountryCode) => void | Called when the country changes. | |
countries? | readonly CountryCode[] | Only these countries can be selected. | |
priority? | readonly CountryCode[] | [defaultCountry] | Countries shown at the top of the list. |
locale? | string | {@link UIProvider} `locale | Language of country names. |
countryName? | string | The selected country code is also submitted in the form under this name (e.g. "phoneCountry"). The number is always submitted as E.164 under name. | |
validate? | boolean | true | A number that doesn't fit the country's length rule makes the field invalid ("Enter a valid phone number"). |
variant? | FieldVariant | CustomVariant<"field"> | Appearance. See FieldVariant. | |
effect? | EffectProp | Effect or effects of the field box (e.g. "glow", ["lift", "beam"]). The accent color is the focus color (--ui-field-focus). Defaults to UIProvider appearance.defaults.field.effect. See BuiltinEffect. | |
className? | string | Classes for the container wrapping the country picker and the number box. |