Skip to content

Forms

Password

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>
  );
}

A password input with a show and hide toggle. It is built on 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

size"sm" | "md" | "lg"

Input size. Defaults to "md".

visibleboolean

Controlled visibility of the value.

defaultVisibleboolean

Initial visibility when uncontrolled. Defaults to false.

onVisibleChange(visible: boolean) => void

Called when the toggle is pressed.

toggleLabelstring

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

leadingIconReactNode

Icon before the text.

invalidboolean

Error state; set automatically inside a <Field error>.

wrapperClassNamestring

Class for the outer wrapper (className goes to the <input>).

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.