Forms & Inputs
@hacline/ui/password-inputPasswordInput
Password input field with an accessible visibility toggle.
Usage
Omit children for a ready-to-use password field with an automatic icon toggle. Configure browser autofill hints via autoComplete.
Click the eye icon to toggle visibility without losing focus.
"use client";
import { Lock } from "lucide-react";
import {
Field,
FieldDescription,
FieldLabel,
} from "@/components/ui/hacline/components/field";
import { PasswordInput } from "@/components/ui/hacline/components/password-input";
export const Example = () => (
<Field className="w-full max-w-sm" name="account-password">
<FieldLabel>Password</FieldLabel>
<PasswordInput
autoComplete="current-password"
defaultValue="Hacline@2026"
placeholder="Enter your password"
prefix={<Lock aria-hidden="true" />}
/>
<FieldDescription>
Click the eye icon to toggle visibility without losing focus.
</FieldDescription>
</Field>
);Form Validation
Pass required, pattern, and inputTitle directly to PasswordInput for native form validation.
"use client";
import { Check, Circle, KeyRound } from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/ui/hacline/components/button";
import {
Field,
FieldDescription,
FieldError,
FieldLabel,
} from "@/components/ui/hacline/components/field";
import { PasswordInput } from "@/components/ui/hacline/components/password-input";
const UPPERCASE_RE = /[A-Z]/u;
const NUMBER_RE = /\d/u;
const SYMBOL_RE = /[^A-Za-z0-9]/u;
const PASSWORD_RULES = [
{
id: "length",
label: "At least 8 characters",
test: (v: string) => v.length >= 8,
},
{
id: "upper",
label: "One uppercase letter",
test: (v: string) => UPPERCASE_RE.test(v),
},
{ id: "number", label: "One number", test: (v: string) => NUMBER_RE.test(v) },
{
id: "symbol",
label: "One special character",
test: (v: string) => SYMBOL_RE.test(v),
},
] as const;
const STRENGTH_META = [
{
color: "bg-hl-border",
label: "Enter a password",
text: "text-hl-fg-muted",
},
{ color: "bg-hl-danger", label: "Weak", text: "text-hl-danger" },
{ color: "bg-hl-warning", label: "Fair", text: "text-hl-warning" },
{ color: "bg-hl-info", label: "Good", text: "text-hl-info" },
{ color: "bg-hl-success", label: "Strong", text: "text-hl-success" },
] as const;
export const Example = () => {
const [value, setValue] = useState("");
const [error, setError] = useState("");
const [submitted, setSubmitted] = useState(false);
const results = PASSWORD_RULES.map((rule) => ({
...rule,
passed: rule.test(value),
}));
const score = results.filter((rule) => rule.passed).length;
const strength = STRENGTH_META[score] ?? STRENGTH_META[0];
const isComplete = score === PASSWORD_RULES.length;
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
if (!isComplete) {
setSubmitted(false);
setError("Please satisfy all password requirements before saving.");
return;
}
setError("");
setSubmitted(true);
};
return (
<form
className="grid w-full max-w-sm gap-3.5"
noValidate
onSubmit={handleSubmit}
>
<Field invalid={Boolean(error)} name="new-password">
<FieldLabel>Create password</FieldLabel>
<PasswordInput
aria-invalid={error ? true : undefined}
autoComplete="new-password"
onValueChange={(next) => {
setValue(next);
setSubmitted(false);
if (error) {
setError("");
}
}}
placeholder="e.g. Hacline@2026"
prefix={<KeyRound aria-hidden="true" />}
required
value={value}
/>
{error ? (
<FieldError>{error}</FieldError>
) : (
<FieldDescription>
Use a mix of letters, numbers, and symbols.
</FieldDescription>
)}
</Field>
<div className="grid gap-2">
<div className="flex items-center justify-between text-xs">
<span className="text-hl-fg-muted">Strength</span>
<span className={`font-medium ${strength.text}`}>
{strength.label}
</span>
</div>
<div aria-hidden="true" className="grid grid-cols-4 gap-1.5">
{PASSWORD_RULES.map((rule, index) => (
<span
className={`h-1.5 rounded-full transition-colors duration-200 ${
index < score ? strength.color : "bg-hl-surface-muted"
}`}
key={rule.id}
/>
))}
</div>
<ul className="mt-1 grid grid-cols-2 gap-x-3 gap-y-1.5 text-xs">
{results.map((rule) => (
<li
className={`flex items-center gap-1.5 transition-colors ${
rule.passed ? "text-hl-fg" : "text-hl-fg-muted"
}`}
key={rule.id}
>
{rule.passed ? (
<Check
aria-hidden="true"
className="text-hl-success size-3.5 shrink-0"
strokeWidth={2.25}
/>
) : (
<Circle
aria-hidden="true"
className="text-hl-border-strong size-3 shrink-0"
/>
)}
<span>{rule.label}</span>
</li>
))}
</ul>
</div>
<div className="flex items-center gap-3">
<Button size="sm" type="submit" variant="primary">
Save password
</Button>
{submitted ? (
<output className="text-hl-success text-xs font-medium">
Password meets all requirements
</output>
) : null}
</div>
</form>
);
};Variants, Sizes & Prefix
Customize appearance with variant ("default" / "filled"), size ("sm" / "md" / "lg"), leading prefix icons, or showToggle={false}.
"use client";
import { Lock, ShieldCheck } from "lucide-react";
import { Field, FieldLabel } from "@/components/ui/hacline/components/field";
import { PasswordInput } from "@/components/ui/hacline/components/password-input";
export const Example = () => (
<div className="grid w-full max-w-lg gap-5">
<div className="grid gap-3 sm:grid-cols-2">
<Field name="variant-default">
<FieldLabel>Default</FieldLabel>
<PasswordInput
defaultValue="hacline-key"
prefix={<Lock aria-hidden="true" />}
variant="default"
/>
</Field>
<Field name="variant-filled">
<FieldLabel>Filled</FieldLabel>
<PasswordInput
defaultValue="hacline-key"
prefix={<ShieldCheck aria-hidden="true" />}
variant="filled"
/>
</Field>
</div>
<div className="grid gap-3 sm:grid-cols-3">
<Field name="size-sm">
<FieldLabel>Small</FieldLabel>
<PasswordInput defaultValue="pass-sm" size="sm" />
</Field>
<Field name="size-md">
<FieldLabel>Medium</FieldLabel>
<PasswordInput defaultValue="pass-md" size="md" />
</Field>
<Field name="size-lg">
<FieldLabel>Large</FieldLabel>
<PasswordInput defaultValue="pass-lg" size="lg" />
</Field>
</div>
<div className="grid gap-3 sm:grid-cols-3">
<Field name="state-invalid">
<FieldLabel>Invalid</FieldLabel>
<PasswordInput aria-invalid defaultValue="1234" size="sm" />
</Field>
<Field name="state-disabled">
<FieldLabel>Disabled</FieldLabel>
<PasswordInput defaultValue="locked-key" disabled size="sm" />
</Field>
<Field name="state-no-toggle">
<FieldLabel>No toggle</FieldLabel>
<PasswordInput placeholder="Confirm PIN" showToggle={false} size="sm" />
</Field>
</div>
</div>
);Parts
Pass custom children when you need full control over inner parts.
| Part | Description |
|---|---|
PasswordInputControl | The native <input>. Its type follows whether the password is shown, and form attributes come from <PasswordInput>. |
PasswordInputToggle | Shows and hides the password. Name it by what it does, like "Show password": it's a toggle button, and aria-pressed says whether the password is shown. |
Props
Prop
Type