Ballmac UI home

Phone Input

A native dialing-code selector paired with a telephone field that preserves the user’s formatting.

Contact number

We will only use this for account recovery.

Installation

$ pnpm dlx shadcn@latest add @ballmac/phone-input

Usage

import { PhoneInput } from "@/components/ballmac/phone-input"

The full example is in the Code tab above.

Examples

States and variants

International contact

API reference

PropTypeDefault
value

National number, controlled by the parent. Formatting is preserved.

string—
defaultValue

Initial national number when uncontrolled.

string""
onValueChange

Called with the edited national number.

(value: string) => void—
countryCode

Controlled international dialing prefix.

string—
defaultCountryCode

Initial dialing prefix when uncontrolled.

string"+1"
onCountryCodeChange

Called when the dialing prefix changes.

(code: string) => void—
countries

Dialing prefixes available in the menu.

PhoneCountry[]defaultCountries
label

Accessible name of the number field.

string—
countryCodeName

Name of the separate country-code form field.

string—

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
Arrow Up / DownChanges the native dialing-code selection
TabMoves to the telephone field

Quality scorecard

7/7

Every applicable check passes

Measured in Chromium 153.0.8010.12 on October 19, 2026, on version 1.0.0, across 2 examples.

How we measure
  • Passed: Accessibility scan

    No serious or critical issues in light and dark, on a phone and a desktop (axe-core 4.13.0, WCAG 2.1 AA and best-practice rules).

  • Passed: Small screens

    No sideways scrolling at 360, 390 or 1280 px wide.

  • Passed: Reduced motion

    No endless animation to begin with.

  • Passed: Right to left

    Mirrors correctly in Arabic, Hebrew, Persian and Urdu layouts (0% of elements off the mirror, limit 15%).

  • Passed: Clean console

    No console errors or React hydration errors while loading.

  • Passed: Keyboard

    4 tab stops, each showing a visible change when it takes focus. 2 documented keys.

  • Not applicable: Loading, empty and error

    Does not show data or take submissions.

  • Passed: Automated tests

    Covered by phone-input.test.tsx.

  • For information: Footprint

    1.3 KB of source (gzip) in 1 file. No extra npm packages.

Automated checks find a subset of problems and do not replace testing with a screen reader and a keyboard in your own app. What they miss.

Use with AI

A native dialing-code selector paired with a telephone field that preserves the user’s formatting. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Phone Input (@ballmac/phone-input) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Collect a contact number with a dialing prefix
  • Edit a national number without forced formatting

Not for

  • Use input type tel when a country selector is unnecessary

Registry JSON: https://ui.ballmac.com/r/phone-input.json

Credits

Free to use in personal and commercial projects.

npm
None

Ballmac UI Pro

Need the whole screen, not one piece?

311 premium blocks (dashboards, settings, calendars, mail, shops, onboarding), a private shadcn registry and Figma tokens. Blocks that show data come with loading, empty and error states built in.

Not ready? Try three Pro blocks free

Leave your email and the blocks appear right here, ready to copy. Yours to use in any project.