Phone Field

Web/Mobile

A 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 aria

Usage

Import
import { SmartphoneIcon } from "lucide-react"

import {
  PhoneField,
  PhoneFieldClear,
  PhoneFieldControl,
  PhoneFieldDescription,
  PhoneFieldInput,
  PhoneFieldLabel,
} from "@/components/cubix/phone-field"
Example
<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.

Structure
PhoneField
├── PhoneFieldLabel
├── PhoneFieldControl
│   ├── Icon data-icon="inline-start" | "inline-end"
│   ├── PhoneFieldInput
│   └── PhoneFieldClear
├── PhoneFieldDescription
└── PhoneFieldError

Accessibility

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.

با className می‌توانید ظاهر را سفارشی کنید.

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

PropTypeDefaultDescription
size"default" | "lg""default"Height for the input: default 40px, lg 48px. Inherited by PhoneFieldInput and PhoneFieldControl unless overridden. Use className for other heights.
disabledbooleanfalseDisables the field and prevents interaction. Forwarded to the control on every base.
invalidbooleanfalseMarks the field as invalid and shows PhoneFieldError when present.
namestring-Identifies the field when a form is submitted. Forwarded to the input on every base.
classNamestring-Additional Tailwind classes merged with the root styles (last one wins).

PhoneFieldControl

PropTypeDefaultDescription
size"default" | "lg"-Overrides the size from PhoneField. Icon inset and height match the default and lg sizes.
childrenReact.ReactNode-Wrap PhoneFieldInput with icons marked data-icon="inline-start" or "inline-end" (same as Button), and optionally PhoneFieldClear.
classNamestring-Additional Tailwind classes merged with the control styles (last one wins).

PhoneFieldInput

PropTypeDefaultDescription
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.
autoCompletestring"tel"Defaults to tel. Override only when a different telephone autocomplete token is required (for example tel-national).
placeholderstring-Hint text shown when the input is empty.
classNamestring-Additional Tailwind classes merged with the input styles (last one wins).
...propsOmit<React.ComponentProps<'input'>, 'type' | 'inputMode' | 'spellCheck'>-Native input attributes (value, onChange, name, required, ...) are forwarded. type, inputMode, and spellCheck stay locked for telephone.

PhoneFieldClear

PropTypeDefaultDescription
aria-labelstring"Clear"Accessible name for the clear button. Required when no visible text is present.
classNamestring-Additional Tailwind classes merged with the clear button styles (last one wins).

PhoneFieldLabel / Description / Error

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the part styles (last one wins).
...propsHTML attributes-Native attributes for the rendered element are forwarded.