# Password input

Password visibility, strength and validation.

Access: pro. Category: Forms. Kind: primitive.

## When to use

- Use it when a product interface needs password visibility, strength and validation.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose form-field instead when a labeled email field with validation and help text is the actual interface need, rather than password input.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Password input

```sh
npx shadcn@latest add @tidal-pro/password-field
```

Stylesheets: `components/ui/tidal.css`, `components/ui/password-field.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/password-field.css";
import{TidalPasswordField}from"./components/ui/password-field";
export default()=><div className="tidal-scope"><TidalPasswordField label={"Demo"}/></div>;
```

## Structured props

- `TidalPasswordField.label: string`: Required label value accepted by this exported component.
- `TidalPasswordField.description?: string | undefined`: Optional description value accepted by this exported component.
- `TidalPasswordField.error?: string | undefined`: Optional error value accepted by this exported component.
- `TidalPasswordField.formatRequirementCount?: ((met: number, total: number) => string) | undefined` (default (met, total) =>
      `${met} of ${total} requirements met`): Optional format requirement count value accepted by this exported component.
- `TidalPasswordField.hideLabel?: string | undefined` (default "Hide password"): Optional hide label value accepted by this exported component.
- `TidalPasswordField.onRevealedChange?: ((revealed: boolean) => void) | undefined`: Callback invoked when the revealed change interaction is proposed.
- `TidalPasswordField.requirements?: Array<TidalPasswordRequirement> | undefined` (default []): Optional requirements value accepted by this exported component.
- `TidalPasswordField.requirementsLabel?: string | undefined` (default "Requirements satisfied"): Optional requirements label value accepted by this exported component.
- `TidalPasswordField.revealed?: boolean | undefined`: Optional revealed value accepted by this exported component.
- `TidalPasswordField.rootClassName?: string | undefined` (default ""): Optional root class name value accepted by this exported component.
- `TidalPasswordField.showLabel?: string | undefined` (default "Show password"): Optional show label value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/password-field.tsx) | [Manifest](https://tidalui.com/examples/password-field.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
import "./components/ui/tidal.css";

import { useEffect, useLayoutEffect, useRef, useState } from "react";

import { ArrowUpRight, Check } from "lucide-react";

import { TidalPasswordField } from "./components/ui/password-field";

import { TidalButton } from "./components/ui/tidal-button";

import "./components/ui/password-field.css";



const tidalExampleStyles = ".password-field-specimen {\n  width: 100%;\n  max-width: 690px;\n  padding: 28px;\n  border: 1px solid var(--t-border);\n  border-radius: var(--t-radius-card);\n  background: var(--t-surface);\n  box-shadow:\n    0 24px 40px -28px #00000030,\n    0 2px 4px #00000007;\n  container-type: inline-size;\n}\n.password-field-specimen > h3 {\n  font-size: 29px;\n  line-height: 1.08;\n  letter-spacing: -1px;\n  font-weight: 500;\n  margin: 13px 0 26px;\n}\n.password-field-specimen > h3 > em {\n  font-family: \"Instrument Serif\", serif;\n  font-size: 1.2em;\n  font-weight: 400;\n}\n.password-demo-frame {\n  overflow: hidden;\n  transition: height 420ms var(--t-ease-out);\n  padding: 7px 0;\n}\n.password-demo-content {\n  display: flow-root;\n}\n.password-demo-layout {\n  display: block;\n  width: min(100%, 480px);\n  margin-inline: auto;\n}\n.password-demo-layout > form {\n  min-width: 0;\n  align-self: center;\n}\n.password-demo-actions {\n  display: flex;\n  flex-wrap: wrap;\n  gap: 9px;\n  margin-top: 24px;\n}\n.tidal-scope .password-demo-actions > .tidal-button {\n  font-size: 11px;\n  padding: 0 12px;\n  flex: 1;\n  min-width: 0;\n}\n.tidal-scope .password-demo-policy-note {\n  font-size: 11px;\n  line-height: 1.6;\n  color: var(--t-muted);\n  margin: 14px 0 0;\n}\n.password-demo-note {\n  font-size: 11px;\n  color: var(--t-muted);\n  line-height: 1.7;\n  margin: 16px 0 0;\n}\n.password-demo-complete {\n  text-align: center;\n  padding: 29px 23px;\n  border: 1px solid var(--t-border);\n  border-radius: 13px;\n  background: var(--t-subtle);\n  animation: password-demo-complete-in 420ms var(--t-ease-out) both;\n}\n.password-demo-complete-icon {\n  display: grid;\n  place-items: center;\n  margin: 0 auto 24px;\n  width: 54px;\n  height: 54px;\n  background: var(--t-ink);\n  color: var(--t-surface);\n  border-radius: 14px;\n  transform: rotate(-5deg);\n  animation: password-demo-check-in 420ms var(--t-ease-spring) both;\n}\n.password-demo-complete > .demo-eyebrow {\n  display: block;\n  font-size: 11px;\n}\n.password-demo-complete > h4 {\n  font-size: 25px;\n  letter-spacing: -0.8px;\n  line-height: 1.2;\n  font-weight: 500;\n  margin: 13px 0;\n}\n.password-demo-complete > p {\n  font-size: 11px;\n  color: var(--t-muted);\n  max-width: 330px;\n  line-height: 1.8;\n  margin: 0 auto 24px;\n}\n.password-demo-complete > .tidal-button {\n  font-size: 11px;\n}\n@media (max-width: 480px) {\n  .password-field-specimen {\n    padding: 20px;\n  }\n  .password-demo-actions {\n    gap: 7px;\n  }\n  .password-demo-complete {\n    padding: 24px 17px;\n  }\n  .password-demo-complete > h4 {\n    font-size: 22px;\n  }\n}\n@keyframes password-demo-complete-in {\n  from {\n    opacity: 0;\n    transform: translateY(8px);\n  }\n  to {\n    opacity: 1;\n    transform: none;\n  }\n}\n@keyframes password-demo-check-in {\n  from {\n    opacity: 0;\n    transform: scale(0.7) rotate(-15deg);\n  }\n  to {\n    opacity: 1;\n    transform: scale(1) rotate(-5deg);\n  }\n}";

const sample = "paper river lantern";

export function PasswordFieldDemo() {
  const [value, setValue] = useState("");
  const [revealed, setRevealed] = useState(false);
  const [phase, setPhase] = useState<"editing" | "checking" | "complete">(
    "editing",
  );
  const [error, setError] = useState("");
  const [height, setHeight] = useState<number>();
  const input = useRef<HTMLInputElement>(null);
  const success = useRef<HTMLHeadingElement>(null);
  const content = useRef<HTMLDivElement>(null);
  const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
  const restore = useRef(false);
  const focusOwner = useRef<HTMLElement | null>(null);
  const requirements = [
    {
      id: "length",
      label: "12 or more characters",
      met: Array.from(value).length >= 12,
    },
    {
      id: "words",
      label: "At least 3 words",
      met: value.trim().split(/\s+/u).filter(Boolean).length >= 3,
    },
  ];
  const satisfied = requirements.filter((r) => r.met).length;
  useEffect(() => () => clearTimeout(timer.current), []);
  useLayoutEffect(() => {
    const active = document.activeElement;
    const canMoveFocus =
      active === document.body || active === focusOwner.current;
    if (phase === "complete" && canMoveFocus) {
      success.current?.focus({ preventScroll: true });
      focusOwner.current = null;
    } else if (phase === "editing" && restore.current) {
      restore.current = false;
      if (canMoveFocus) input.current?.focus({ preventScroll: true });
      focusOwner.current = null;
    }
  }, [phase]);
  useLayoutEffect(() => {
    const node = content.current;
    if (!node) return;
    const measure = () => {
      const parent = getComputedStyle(node.parentElement!);
      setHeight(
        node.offsetHeight +
          Number.parseFloat(parent.paddingTop) +
          Number.parseFloat(parent.paddingBottom),
      );
    };
    measure();
    const observer = new ResizeObserver(measure);
    observer.observe(node);
    return () => observer.disconnect();
  }, []);
  function reset() {
    clearTimeout(timer.current);
    focusOwner.current =
      document.activeElement instanceof HTMLElement
        ? document.activeElement
        : null;
    setValue("");
    setRevealed(false);
    setError("");
    restore.current = true;
    setPhase("editing");
    if (phase === "editing") {
      restore.current = false;
      input.current?.focus({ preventScroll: true });
    }
  }
  return (
    <div className="password-field-specimen">
      <div className="password-demo-frame" style={{ height }}>
        <div ref={content} className="password-demo-content">
          {phase === "complete" ? (
            <div className="password-demo-complete">
              <span className="password-demo-complete-icon" aria-hidden="true">
                <Check size={25} />
              </span>
              <span className="demo-eyebrow">SAMPLE CHECK COMPLETE</span>
              <h4 ref={success} tabIndex={-1}>
                Ready for the next step.
              </h4>
              <p>
                Both sample requirements were met. This preview created no
                account and saved no password.
              </p>
              <TidalButton variant="secondary" onClick={reset}>
                Try the sample again
              </TidalButton>
            </div>
          ) : (
            <>
              <div className="password-demo-layout">
                <form
                  noValidate
                  onSubmit={(event) => {
                    event.preventDefault();
                    if (satisfied !== 2) {
                      setError(
                        "Complete both sample requirements to continue.",
                      );
                      input.current?.focus({ preventScroll: true });
                      return;
                    }
                    focusOwner.current =
                      (event.nativeEvent as SubmitEvent).submitter instanceof
                      HTMLElement
                        ? (event.nativeEvent as SubmitEvent).submitter
                        : document.activeElement instanceof HTMLElement
                          ? document.activeElement
                          : null;
                    setError("");
                    setRevealed(false);
                    setPhase("checking");
                    timer.current = setTimeout(() => {
                      setValue("");
                      setPhase("complete");
                    }, 650);
                  }}
                >
                  <TidalPasswordField
                    ref={input}
                    label="Sample passphrase"
                    name="sample-passphrase"
                    placeholder="Start with a few words…"
                    value={value}
                    onChange={(event) => {
                      setValue(event.target.value);
                      setError("");
                    }}
                    revealed={revealed}
                    onRevealedChange={setRevealed}
                    autoComplete="off"
                    required
                    disabled={phase === "checking"}
                    description="Use the provided fictional phrase to explore."
                    error={error}
                    requirements={requirements}
                    requirementsLabel="Sample requirements"
                    formatRequirementCount={(met, total) =>
                      `${met} of ${total} checks met`
                    }
                  />
                  <div className="password-demo-actions">
                    <TidalButton
                      type="button"
                      variant="secondary"
                      onClick={() => {
                        if (phase === "checking") {
                          reset();
                          return;
                        }
                        setValue(sample);
                        setError("");
                        input.current?.focus({ preventScroll: true });
                      }}
                    >
                      {phase === "checking"
                        ? "Cancel check"
                        : "Use sample phrase"}
                    </TidalButton>
                    <TidalButton type="submit" loading={phase === "checking"}>
                      Check sample
                      <ArrowUpRight size={13} aria-hidden="true" />
                    </TidalButton>
                  </div>
                  <p className="password-demo-policy-note">
                    Illustrative requirements, not a password-strength rating.
                  </p>
                </form>
              </div>
            </>
          )}
        </div>
      </div>
      <p className="password-demo-note">
        This form runs in your browser. No account is created and no password is
        saved.
      </p>
    </div>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <PasswordFieldDemo />
    </div>
  );
}

```

## Gotchas

- Keep field state, validation results, submission, and persistence in the host form workflow.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Required visible label. Native controlled value/onChange or uncontrolled defaultValue, all native input attributes/ref, required, readOnly, disabled, id, className(input) and rootClassName supported; type is managed internally. Native current-password autocomplete by default; use new-password for creation. Optional description/error compose IDs with external aria-describedby; error sets aria-invalid and role=alert. Visibility is internally managed by default or controlled with revealed/onRevealedChange; controlled visibility without a callback disables toggle. Localizable showLabel/hideLabel. Native 44px toggle has aria-pressed/controls and supports Enter/Space; pointer reveal preserves active input selection/focus, keyboard reveal retains toggle focus, disabled disables both controls, readOnly still allows visibility changes. Requirements are an optional caller-evaluated array of stable id/label/met; count and progressbar derive only from met values, no strength rating or security guarantee. Localizable requirementsLabel/formatRequirementCount. Checklist exposes Met/Not met text; no per-keystroke live announcements. Persistent rail, drawn checks/slash, finite reveal veil and focus icon motion honor reduced motion. No duplicated password text, collection, storage, submission or wrapper form is introduced. Consumers own policy evaluation, authentication, validation and request handling.
