Text Field

Web/Mobile

A labeled plain-text field with optional icons, clear, description, and error - for names, usernames, and other free text. Email, phone, password, and similar inputs are separate components.

نام کامل خود را وارد کنید.

Installation

pnpm dlx cubix-ui@latest add text-field

Usage

Import
import {
  TextField,
  TextFieldClear,
  TextFieldControl,
  TextFieldDescription,
  TextFieldInput,
  TextFieldLabel,
} from "@/components/cubix/text-field"
Example
<TextField className="w-full max-w-sm">
  <TextFieldLabel>نام و نام خانوادگی</TextFieldLabel>
  <TextFieldControl>
    <Icon data-icon="inline-start" />
    <TextFieldInput defaultValue="امین ابدالی" placeholder="نام کامل" />
    <TextFieldClear aria-label="پاک کردن" />
  </TextFieldControl>
  <TextFieldDescription>نام کامل خود را وارد کنید.</TextFieldDescription>
</TextField>

Composition

Compose label, control, help text, and error as siblings under TextField. Wrap the input in TextFieldControl when you need icons or a clear button - mark icons with data-icon like Button so spacing follows the reading direction. TextFieldClear appears only while the input has a value.

Structure
TextField
├── TextFieldLabel
├── TextFieldControl
│   ├── Icon data-icon="inline-start" | "inline-end"
│   ├── TextFieldInput
│   └── TextFieldClear
├── TextFieldDescription
└── TextFieldError

Accessibility

TextFieldLabel is wired to the input, and TextFieldDescription and TextFieldError are announced through aria-describedby. invalid sets aria-invalid on the input. Give TextFieldClear 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 TextFieldError.

فقط حروف انگلیسی، عدد و زیرخط مجاز است.

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 TextFieldControl with data-icon like Button so spacing follows the reading direction.

Clear

TextFieldClear 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 (text-field, text-field-label, text-field-control, text-field-input, text-field-clear, text-field-description, text-field-error) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.

TextField

PropTypeDefaultDescription
size"default" | "lg""default"Height for the input: default 40px, lg 48px. Inherited by TextFieldInput and TextFieldControl 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 TextFieldError when present.
namestring-Identifies the field when a form is submitted. Forwarded to TextFieldInput on every base.
classNamestring-Additional Tailwind classes merged with the root styles (last one wins).

TextFieldControl

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

TextFieldInput

PropTypeDefaultDescription
size"default" | "lg"-Overrides the size from TextField. Default 40px, lg 48px. Use className for other heights.
placeholderstring-Hint text shown when the input is empty.
classNamestring-Additional Tailwind classes merged with the input styles (last one wins).
...propsReact.ComponentProps<'input'>-Native input attributes (value, onChange, name, required, autoComplete, ...) are forwarded. Prefer specialized field components for email, phone, password, and similar inputs.

TextFieldClear

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).

TextFieldLabel / 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.