Phone Field
Web/MobileA labeled mobile phone field with icons, clear, description, and error. type is locked to tel with matching autocomplete and inputMode.
Installation
pnpm dlx cubix-ui@latest add phone-field --base ariaUsage
import { SmartphoneIcon } from "lucide-react"
import {
PhoneField,
PhoneFieldClear,
PhoneFieldControl,
PhoneFieldDescription,
PhoneFieldInput,
PhoneFieldLabel,
} from "@/components/cubix/phone-field"
<PhoneField className="w-full max-w-sm">
<PhoneFieldLabel>شماره همراه</PhoneFieldLabel>
<PhoneFieldControl>
<SmartphoneIcon data-icon="inline-start" />
<PhoneFieldInput defaultValue="۰۹۱۲۳۴۵۶۷۸۹" placeholder="۰۹۱۲۰۰۰۰۰۰۰" />
<PhoneFieldClear aria-label="پاک کردن" />
</PhoneFieldControl>
<PhoneFieldDescription>
برای ورود و بازیابی حساب از این شماره استفاده میشود.
</PhoneFieldDescription>
</PhoneField>
Composition
Same composition as Text Field. PhoneFieldInput always renders type="tel" with telephone autocomplete and inputMode, so mobile keyboards open the dial pad.
PhoneField
├── PhoneFieldLabel
├── PhoneFieldControl
│ ├── Icon data-icon="inline-start" | "inline-end"
│ ├── PhoneFieldInput
│ └── PhoneFieldClear
├── PhoneFieldDescription
└── PhoneFieldErrorAccessibility
PhoneFieldLabel is wired to the input, and PhoneFieldDescription and PhoneFieldError are announced through aria-describedby. invalid sets aria-invalid on the input. Give PhoneFieldClear a localized aria-label; it leaves the tab order while hidden.
Examples
Description
Add helper text below the control for format hints or guidance.
Invalid
Set invalid on the root to apply destructive styles and show PhoneFieldError.
Disabled
Disable the field to block interaction. The control uses a muted fill; label and description stay readable.
Sizes
Two heights ship by default: default (40px) and lg (48px). Use className for any other size.
Icons
Place icons inside PhoneFieldControl with data-icon like Button so spacing follows the reading direction.
Clear
PhoneFieldClear appears inside the control while the input has a value and returns focus to the input after clearing.
In a form
Set name on the root so the value is submitted with the form, and pair the field with Cubix Button.
Custom styling
Every part accepts a className merged with the shipped cn helper. Here the input uses a filled surface instead of the default outline.
API Reference
Note: Parts render data-slot attributes (phone-field, phone-field-label, phone-field-control, phone-field-input, phone-field-clear, phone-field-description, phone-field-error) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.
PhoneField
| Prop | Type | Default | Description |
|---|---|---|---|
| size | "default" | "lg" | "default" | Height for the input: default 40px, lg 48px. Inherited by PhoneFieldInput and PhoneFieldControl unless overridden. Use className for other heights. |
| disabled | boolean | false | Disables the field and prevents interaction. Forwarded to the control on every base. |
| invalid | boolean | false | Marks the field as invalid and shows PhoneFieldError when present. |
| name | string | - | Identifies the field when a form is submitted. Forwarded to the input on every base. |
| className | string | - | Additional Tailwind classes merged with the root styles (last one wins). |
PhoneFieldControl
| Prop | Type | Default | Description |
|---|---|---|---|
| size | "default" | "lg" | - | Overrides the size from PhoneField. Icon inset and height match the default and lg sizes. |
| children | React.ReactNode | - | Wrap PhoneFieldInput with icons marked data-icon="inline-start" or "inline-end" (same as Button), and optionally PhoneFieldClear. |
| className | string | - | Additional Tailwind classes merged with the control styles (last one wins). |
PhoneFieldInput
| Prop | Type | Default | Description |
|---|---|---|---|
| type | "tel" | "tel" | Locked to tel. Cannot be changed. inputMode is always tel and spellCheck is always false. |
| size | "default" | "lg" | - | Overrides the size from PhoneField. Default 40px, lg 48px. Use className for other heights. |
| autoComplete | string | "tel" | Defaults to tel. Override only when a different telephone autocomplete token is required (for example tel-national). |
| placeholder | string | - | Hint text shown when the input is empty. |
| className | string | - | Additional Tailwind classes merged with the input styles (last one wins). |
| ...props | Omit<React.ComponentProps<'input'>, 'type' | 'inputMode' | 'spellCheck'> | - | Native input attributes (value, onChange, name, required, ...) are forwarded. type, inputMode, and spellCheck stay locked for telephone. |
PhoneFieldClear
| Prop | Type | Default | Description |
|---|---|---|---|
| aria-label | string | "Clear" | Accessible name for the clear button. Required when no visible text is present. |
| className | string | - | Additional Tailwind classes merged with the clear button styles (last one wins). |
PhoneFieldLabel / Description / Error
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the part styles (last one wins). |
| ...props | HTML attributes | - | Native attributes for the rendered element are forwarded. |