Dashral Pro is hereSee pricing

Dashral

Phone InputNew

A phone number with its country, grouped as it's typed and given in international form.

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

Stored as: —

Installation

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

Adds the component, the components it builds on, its npm packages and the theme tokens it uses. Or by its full URL: https://dashral.com/r/phone-input.json

Usage

example.tsx
import { PhoneInput } from "@/components/dashral/phone-input"

<PhoneInput label="Phone" name="phone" defaultCountry="ID" onValueChange={(phone) => setPhone(phone)} />

Using the npm package? Import from @dashral/ui/components/phone-input instead, here and in the examples; the rest is the same.

Examples

Preferred countries

Listed first; paste a number with its code (+65 …) and the country follows.

For delivery updates only.

In a form

name sends the international number; countries limits the list; an error after submitting.

API reference

PhoneInput

Also takes every prop of Input(opens in a new tab).

PropTypeDefault
labelReactNode

Shown above, linked to the control.

—
descriptionReactNode

A hint under the control.

—
errorboolean | ReactNode

true shows the error style; a message also shows under the control.

—
labelActionReactNode

At the end of the label's row, e.g. a “Forgot password?” link or the current value.

—
withAsteriskboolean

Marks the label with an asterisk, e.g. alongside required.

false
value / defaultValuestring

The number in international form (E.164): "+6281234567890".

""
onValueChange(value, { country, national }) => void

The international number ("" when empty), the country and the digits typed.

—
country / defaultCountry / onCountryChangestring

The country picked (ISO 3166: "ID"), controlled or first. Without one, it follows the number given.

"US"
countriesstring[]

Only these in the list.

every country
preferredCountriesstring[]

Listed first, above the rest.

—
namestring

The form field's name; the international number is sent.

—
placeholder / disabled / required

As on Input.

—
classNames{ root, label, wrapper, input, description, error, trigger, content }

Classes for each part; trigger is the country button, content its list.

—
classNamestring

Extra classes, merged with cn() so yours win.

—

Keyboard

KeysAction
EnterorSpaceOpen the countries (on the flag)
TypeSearch the countries by name or code
↓or↑ and EnterMove through them and pick one

Accessibility

  • With label, description or error, the id, aria-describedby and aria-invalid are wired up for you.
  • The country button is named "Country" and the country picked; country names are in the page's language (Intl).
  • type="tel" with autocomplete="tel", so phones show the number pad and browsers fill it in.