Password Field

Web/Mobile

A labeled password field with icons, visibility toggle, description, and error. type switches between password and text when revealed.

حداقل ۸ کاراکتر، شامل حرف و عدد.

Installation

pnpm dlx cubix-ui@latest add password-field --base radix

Usage

Import
import { LockKeyholeIcon } from "lucide-react"

import {
  PasswordField,
  PasswordFieldControl,
  PasswordFieldDescription,
  PasswordFieldInput,
  PasswordFieldLabel,
  PasswordFieldToggle,
} from "@/components/cubix/password-field"
Example
<PasswordField className="w-full max-w-sm">
  <PasswordFieldLabel>رمز عبور</PasswordFieldLabel>
  <PasswordFieldControl>
    <LockKeyholeIcon data-icon="inline-start" />
    <PasswordFieldInput defaultValue="CubixPass123!" placeholder="رمز عبور خود را وارد کنید" />
    <PasswordFieldToggle />
  </PasswordFieldControl>
  <PasswordFieldDescription>حداقل ۸ کاراکتر، شامل حرف و عدد.</PasswordFieldDescription>
</PasswordField>

Composition

Same composition as Text Field, with PasswordFieldToggle in place of the clear button. PasswordFieldInput starts as type="password" with current-password autocomplete and switches to text while revealed. The input defaults to dir="ltr" so trailing symbols stay in place in right-to-left forms.

Structure
PasswordField
├── PasswordFieldLabel
├── PasswordFieldControl
│   ├── Icon data-icon="inline-start" | "inline-end"
│   ├── PasswordFieldInput
│   └── PasswordFieldToggle
├── PasswordFieldDescription
└── PasswordFieldError

Accessibility

PasswordFieldToggle swaps its accessible name between showLabel and hideLabel and returns focus to the input after each press. PasswordFieldDescription and PasswordFieldError are announced through aria-describedby, and invalid sets aria-invalid on the input.

Examples

Visibility toggle

Pass defaultVisible on the root to start revealed.

با دکمه چشم می‌توانید رمز را نمایش یا مخفی کنید.

Controlled

Pass visible and onVisibleChange to own the visibility state from outside.

وضعیت: رمز عبور مخفی است

Description

Add helper text below the control for strength hints. Use autoComplete="new-password" when creating a password.

از ترکیب حروف بزرگ، کوچک، عدد و نماد استفاده کنید.

Invalid

Set invalid on the root to apply destructive styles and show PasswordFieldError.

Disabled

Disable the field to block the input and toggle. 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 PasswordFieldControl with data-icon like Button so spacing follows the reading direction.

In a form

Set name on the root so the value is submitted with the form, and pair the field with Cubix Button.

ورود به حساب

رمز عبور حساب Cubix خود را وارد کنید.

حداقل ۸ کاراکتر، شامل حرف و عدد.

Custom styling

Every part accepts a className merged with the shipped cn helper. When the toggle sits in the control, style PasswordFieldControl for a filled surface instead of the default outline.

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

API Reference

Note: Parts render data-slot attributes (password-field, password-field-label, password-field-control, password-field-input, password-field-toggle, password-field-description, password-field-error) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.

PasswordField

PropTypeDefaultDescription
size"default" | "lg""default"Height for the input: default 40px, lg 48px. Inherited by PasswordFieldInput and PasswordFieldControl unless overridden. Use className for other heights.
disabledbooleanfalseDisables the field, input, and visibility toggle. Forwarded on every base.
invalidbooleanfalseMarks the field as invalid and shows PasswordFieldError when present.
visibleboolean-Controlled visibility. When true, the input type is text; when false, password. Pair with onVisibleChange.
defaultVisiblebooleanfalseInitial visibility for uncontrolled use. Defaults to hidden (password).
onVisibleChange(visible: boolean) => void-Called when PasswordFieldToggle changes visibility.
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).

PasswordFieldControl

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

PasswordFieldInput

PropTypeDefaultDescription
type"password" | "text""password"Locked to password when hidden and text when PasswordFieldToggle reveals the value. Cannot be set manually. spellCheck is always false.
size"default" | "lg"-Overrides the size from PasswordField. Default 40px, lg 48px. Use className for other heights.
autoCompletestring"current-password"Defaults to current-password. Use "new-password" for create or reset flows.
dir"ltr" | "rtl" | "auto""ltr"Passwords are typed in Latin, so the input defaults to ltr and trailing symbols stay in place when the value is revealed. Text still aligns with the surrounding form direction.
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' | 'spellCheck'>-Native input attributes (value, onChange, name, required, ...) are forwarded. type and spellCheck stay locked.

PasswordFieldToggle

PropTypeDefaultDescription
showLabelstring"نمایش رمز عبور"Accessible name while the password is hidden. Used as aria-label on the toggle, which swaps names instead of using aria-pressed.
hideLabelstring"مخفی کردن رمز عبور"Accessible name while the password is visible. Used as aria-label on the toggle.
classNamestring-Additional Tailwind classes merged with the toggle button styles (last one wins).

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