# Password

> Password input with an animated show and hide toggle, controlled or uncontrolled visibility and Field support.

Source: https://docs.cherry.al/components/password

> For the complete documentation index, see [llms.txt](https://docs.cherry.al/llms.txt).

# Password

<Preview bleed>
<iframe className="light-only" src="https://v2.cherry.al/preview/password?theme=light" title="Password preview" loading="lazy" style={{ width: "100%", height: "566px" }} />
<iframe className="dark-only" src="https://v2.cherry.al/preview/password?theme=dark" title="Password preview" loading="lazy" style={{ width: "100%", height: "566px" }} />

```tsx
"use client";
import { Field, Password } from "@cherry-design-system/react";

export function SignInPassword() {
  return (
    <Field label="Password">
      <Password name="password" autoComplete="current-password" />
    </Field>
  );
}
```
</Preview>

A password input with a show and hide toggle. It is built on [Input](/components/input), so it shares its sizes, leading icon and error state.

## Examples

### With a leading icon

```tsx
"use client";
import { Field, Password } from "@cherry-design-system/react";
import { Lock } from "lucide-react";

export function NewPassword() {
  return (
    <Field label="New password" hint="At least 12 characters.">
      <Password autoComplete="new-password" leadingIcon={<Lock />} minLength={12} />
    </Field>
  );
}
```

### Controlled visibility

```tsx
"use client";
import { useState } from "react";
import { Field, Password } from "@cherry-design-system/react";

export function ApiSecret() {
  const [visible, setVisible] = useState(false);
  return (
    <Field label="Client secret">
      <Password
        visible={visible}
        onVisibleChange={setVisible}
        toggleLabel="Show client secret"
        readOnly
        defaultValue="cs_9f2a7c"
      />
    </Field>
  );
}
```

## Properties

<Field value="size" type='"sm" | "md" | "lg"'>
  Input size. Defaults to `"md"`.
</Field>

<Field value="visible" type="boolean">
  Controlled visibility of the value.
</Field>

<Field value="defaultVisible" type="boolean">
  Initial visibility when uncontrolled. Defaults to `false`.
</Field>

<Field value="onVisibleChange" type="(visible: boolean) => void">
  Called when the toggle is pressed.
</Field>

<Field value="toggleLabel" type="string">
  Name of the show/hide button. It is a toggle, so `aria-pressed` carries the state and the name stays the same. Defaults to `"Show password"`.
</Field>

<Field value="leadingIcon" type="ReactNode">
  Icon before the text.
</Field>

<Field value="invalid" type="boolean">
  Error state; set automatically inside a `<Field error>`.
</Field>

<Field value="wrapperClassName" type="string">
  Class for the outer wrapper (`className` goes to the `<input>`).
</Field>

Accepts the other Input props and native `<input>` attributes except `type` and `suffix`. The ref goes to the `<input>`.

## Styling

Root class `cherry-password` (on the Input wrapper) with `data-size` (`sm`, `md`, `lg`) and states `data-invalid`, `data-disabled`. The toggle is `cherry-password__toggle` with `aria-pressed`; the eye glyph parts are `cherry-password__icon`, `__eye`, `__lid`, `__pupil` and `__lashes`. The Input classes (`cherry-input`, `cherry-input__control`) apply too.

## Accessibility

The reveal button is labelled (`toggleLabel`) and exposes `aria-pressed`. Label the field like Input, with Field or `aria-label`. Set `autoComplete` to `current-password` or `new-password` so password managers can help.

<Button href="https://github.com/cherry-design-system/react/tree/main/src/components/password" icon="code" iconPosition="left">
  View Source
</Button>
