Phone Input
FormInternational phone number input with country code selector and formatting.
Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.
"use client";
import { PhoneInput } from "@dashboardpack/core/components/ui/phone-input";
import { useState } from "react";
export default function PhoneInputExample() {
const [phone, setPhone] = useState("");
return (
<div className="w-full max-w-sm space-y-3">
<p id="phone-help" className="text-sm font-medium">
Contact number
</p>
<PhoneInput
value={phone}
onChange={setPhone}
defaultCountry="GB"
placeholder="Enter phone number"
/>
<p className="text-xs text-muted-foreground">
Choose a country to format a local number. Value: {phone || "Empty"}
</p>
</div>
);
}Usage
Keep the formatted display value in state. defaultCountry initializes the country selector; it is not a controlled country prop. Validate and normalize the number before storing it on a backend.
import { PhoneInput } from "@dashboardpack/core/components/ui/phone-input";Available in the included @dashboardpack/core package. Copy the complete example from Source code for all imports and state. Add "use client" when using hooks or event handlers. See installation and theming for project setup.
API reference
Common props and defaults. Slot-specific props are named below; native elements also accept their standard HTML attributes. The component TypeScript definitions are the complete type reference.
| Prop | Type / Default | Description |
|---|---|---|
| value | stringDefault: required | Formatted input value. |
| onChange | (value: string) => voidDefault: required | Receives formatted text. |
| defaultCountry | CountryCodeDefault: US | Initial country, using a two-letter code. |
| placeholder | stringDefault: Phone number | Empty input hint. |
| disabled | booleanDefault: false | Disable input and country selection. |