Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Autocomplete
- Avatar
- Badge
- Bar List
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Carousel
- Checkbox
- Checkbox Group
- Circular Progress
- Collapsible
- Combobox
- Command
- Context Menu
- Currency Input
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Menubar
- Meter
- Multi Combobox
- Native Select
- Navigation Menu
- Number Field
- Pagination
- Phone Input
- Popover
- Progress
- Progress List
- Prompt
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Stat
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
- Typography
Loading...
"use client";
import { useState } from "react";
import { Label } from "@/components/ui/label";
import { PhoneInput } from "@/components/ui/phone-input";
export function PhoneInputDemo() {
const [value, setValue] = useState("");
return (
<div className="grid w-full max-w-sm gap-2">
<Label htmlFor="account-phone">Account phone</Label>
<PhoneInput
className="w-full"
clearable
defaultCountry="US"
id="account-phone"
onChange={setValue}
onClear={() => setValue("")}
placeholder="Enter account phone"
value={value}
/>
<p className="text-muted-foreground text-sm">
{value
? `Stored as E.164: ${value}`
: "Used for login recovery and billing alerts."}
</p>
</div>
);
}Installation
npx shadcn@latest add "https://ui.blode.co/r/styles/default/phone-input"
Usage
"use client";
import { useState } from "react";
import { PhoneInput } from "@/components/ui/phone-input";
export function Example() {
const [value, setValue] = useState("");
return (
<PhoneInput
defaultCountry="US"
onChange={setValue}
placeholder="Enter phone number"
value={value}
/>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Class name applied to the input element. |
placeholder | string | Enter phone number | Placeholder shown when no value is present. |
value | string | - | Controlled phone number value. |
onChange | (value: string) => void | - | Callback fired when the value changes. |
defaultCountry | string | - | Initial selected country code, for example US. |
fallbackCountry | string | "US" | Used when defaultCountry is not provided. |
clearable | boolean | false | Shows a clear button when a value exists. |
onClear | () => void | - | Callback fired when the clear button is used. |
clearClassName | string | - | Class name applied to the clear button. |
disabled | boolean | false | Disables both country picker and number input. |
onCountryChange | (country: string | undefined) => void | - | Callback fired when the selected country changes. |