---
title: "Phone Field"
description: "A field for a phone number and its country. Pick the country from a list with flags and search, and the number formats as you type."
url: https://gelatinui.com/components/phone-field
markdown_url: https://gelatinui.com/components/phone-field.md
access: free
install: "npx shadcn@latest add @gelatin-ui/phone-field"
registry_item: https://gelatinui.com/r/phone-field.json
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Phone Field

> A field for a phone number and its country. Pick the country from a list with flags and search, and the number formats as you type.

Page: https://gelatinui.com/components/phone-field

## When to use it

Best for: A phone number with its country: pick from a list or type the + code, and get E.164.

- Use it to ask for a phone number from more than one country.
- Use `phoneFormat="national"` to show the dial code in the trigger.
- Use `countries` to limit the list. With one country, there is no list.
- Use `name` on `PhoneFieldInput` to submit E.164 with a form.

## When not to use it

- For another fixed text format, such as a card number, use a [Masked Input](https://gelatinui.com/components/masked-input.md).
- For a one-time code sent to the phone, use an [Input OTP](https://gelatinui.com/components/input-otp.md).

## Notes for agents

- `value` is the number as shown. `onValueChange` gets E.164 first, or `null` while the number is not possible.
- In international format, the typed + code also sets the country.
- `metadata` is `min` by default. Pass `max` for exact `valid` and `type`.
- Use `check="valid"` with `max` metadata. `possible`, the default, checks only the length.
- `locale` sets the language of the country names. It is `en` by default.
- `PhoneFieldError` shows after a blur or with `showErrors`. With `required`, an empty number is an error too.
- A paste of a national number ("030 901820") or one with 00 ("0049 30 901820") gets the + code of the picked country.
- Pass `renderFlag` for your own flags. Return `null` for no flags.
- Translate the texts with `labels`. `{country}` is the country name.

## Anatomy

```text
PhoneField
├─ PhoneFieldLabel (0..n)
├─ PhoneFieldGroup (0..n)
├─ PhoneFieldFlag (0..n)
├─ PhoneFieldCountry (0..n)
├─ PhoneFieldInput (0..n)
└─ PhoneFieldError (0..n)
```

## API reference

### PhoneField

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `disabled` | `boolean` | false |  |
| `value` | `string` |  | The number as shown (controlled). |
| `defaultValue` | `string` | "" |  |
| `onValueChange` | `function` |  | Runs on every change with E.164 (or `null` while not possible) and every detail. |
| `country` | `CountryCode \| null` |  | The country (controlled). In international format the typed + code also sets it. |
| `defaultCountry` | `CountryCode` |  |  |
| `onCountryChange` | `function` |  |  |
| `phoneFormat` | `"international" \| "national"` | "international" | `international` (default): "+49 30 901820". `national`: "030 901820", the dial code in the trigger. |
| `countries` | `readonly CountryCode[]` |  | Limit the list (in this order). One country: no list, no chevron. |
| `metadata` | `MetadataJson` | PHONE_METADATA | libphonenumber-js metadata: `min` by default; `max` for exact `valid` and `type`. |
| `check` | `"possible" \| "valid"` | "possible" | `possible` (default): the length fits. `valid`: the country ranges (use with `max`). |
| `locale` | `string` |  | The language of the country names (`Intl.DisplayNames`). Default `en`, the same on server and client. |
| `renderFlag` | `function` |  | Your own flags (static imports for the server HTML, another set, or none: return `null`). |
| `labels` | `Partial<Record<PhoneFieldText, string>>` |  | The texts (translate them). `{country}` is the country name. |
| `readOnly` | `boolean` | false |  |
| `showErrors` | `boolean` | false | Show the error now, as after a submit. |
| `required` | `boolean` | false | An empty number is an error (`labels.required`) after a blur or with `showErrors`. |

### PhoneFieldLabel

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### PhoneFieldGroup

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "lg" \| "sm" \| "xs"` |  |  |
| `variant` | `"dashed" \| "default"` |  |  |
| `className` | `string` |  |  |

### PhoneFieldFlag

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `locale` | `string` |  | The language of the name (`Intl.DisplayNames`). Default: the `DisplayLocaleProvider` locale. |
| `pop` | `boolean` |  | Pop the art in when `code` changes: scale 0.9 to 1 and a fade on the popup clock. |
| `variant` | `"circle" \| "rectangle" \| "square"` |  |  |
| `country` | `CountryCode \| null` |  | The country, or `null` for the globe. Default: the country of the field. |

### PhoneFieldCountry

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `align` | `"block-end" \| "block-start" \| "inline-end" \| "inline-start"` |  |  |

### PhoneFieldInput

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `name` | `string` |  | Submit E.164 under this name (a hidden input). |
| `className` | `string` |  |  |
| `guide` | `boolean` |  | The ghost guide of the slots still to fill, while the input has focus. Default `true`. |
| `rawName` | `string` |  | Also submit the raw value under this name (a hidden input), next to the shown one. |
| `rejectFeedback` | `boolean` |  | Nudge the field 2px when the mask rejects a key. Default `true`. |
| `onReject` | `function` |  | Runs when the mask rejects a key (a letter in a number, a 13th month). |
| `ref` | `Ref<HTMLInputElement>` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "lg" \| "sm" \| "xs"` |  |  |

### PhoneFieldError

No props of its own: `className`, `children`, and every other prop go to the element it renders.

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| PhoneField | `phone-field` |  |  |  |
| PhoneFieldLabel | `phone-field-label` |  |  |  |
| PhoneFieldGroup | `phone-field-group` |  |  |  |
| PhoneFieldFlag | `phone-field-flag` |  |  |  |
| PhoneFieldCountry | `phone-field-country` | `data-popup-open`, `data-rounded`, `data-size` | `--radius` |  |
| PhoneFieldInput | `phone-field-input` |  |  |  |
| PhoneFieldError | `phone-field-error` |  |  |  |

## Usage

Put `PhoneFieldGroup` inside `PhoneField`, and `name` on `PhoneFieldInput` to submit E.164. `onValueChange` gets E.164 first, or `null` while the number is not possible.

```tsx title="contact-phone.tsx"
import {
  PhoneField,
  PhoneFieldCountry,
  PhoneFieldError,
  PhoneFieldGroup,
  PhoneFieldInput,
  PhoneFieldLabel,
} from "@/components/ui/phone-field";

export function ContactPhone() {
  return (
    <PhoneField defaultCountry="DE" required>
      <PhoneFieldLabel>Phone</PhoneFieldLabel>
      <PhoneFieldGroup>
        <PhoneFieldCountry />
        <PhoneFieldInput name="phone" />
      </PhoneFieldGroup>
      <PhoneFieldError />
    </PhoneField>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/phone-field
```

It adds 63 registry items: 60 files, 10168 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@maskito/core`, `@maskito/kit`, `@maskito/phone`, `@maskito/react`, `@phosphor-icons/react`, `@tanstack/react-virtual`, `clsx`, `country-flag-icons`, `libphonenumber-js`, `motion`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Combobox](https://gelatinui.com/components/combobox.md)
- [Country Flag](https://gelatinui.com/components/country-flag.md)
- [Input Group](https://gelatinui.com/components/input-group.md)
- [Masked Input](https://gelatinui.com/components/masked-input.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Masked Input](https://gelatinui.com/components/masked-input.md)
- [Field](https://gelatinui.com/components/field.md)
- [Combobox](https://gelatinui.com/components/combobox.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Enter, Space, Arrow Down | On `PhoneFieldCountry`: opens the country list. |
| Arrow keys | In the list: moves through the countries. |
| Enter | In the list: picks the country. |
| Escape | Closes the country list. |

## Accessibility

`PhoneFieldLabel` names the number input, and the country list is a button with its own name.

`PhoneFieldError` shows after a blur or with `showErrors`.

Translate the texts with `labels`, and set the language of the country names with `locale`.

## Motion

| Part | Motion |
| --- | --- |
| Open | popup · 150ms · ease-panel (0.2, 0.4, 0.2, 1) · fades in and scales from 95% |
| Close | popup-exit · 120ms · ease-out (0, 0, 0.2, 1) |
