Password Input
Password Input for a useful, keyboard-friendly product interface.
Make it yours.
Install the editable source and its dependencies into your React + Tailwind project.
Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/password-input.jsonUse it
Scroll horizontally for long lines
"use client";
import {PasswordInput} from '@/components/jez-ui/ui/password-input';
export default function Example(){
return <><div className="w-full max-w-sm"><div className="mb-7"><h3 className="text-2xl tracking-tight">Keep it between us.</h3><p className="mt-2 text-sm leading-relaxed text-muted-foreground">A strong password is a good place to start.</p></div><PasswordInput placeholder="Your password"/></div></>;
}Props & types
Scroll horizontally for long lines
Omit<React.ComponentProps<typeof Input>, "type">Source
View 3 source files
registry/ui/password-input.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { Eye, EyeOff, LockKeyhole } from "lucide-react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { Input } from "./input";
import { cn } from "./utils";
export function PasswordInput({
className,
...props
}: Omit<React.ComponentProps<typeof Input>, "type">) {
const [visible, setVisible] = React.useState(false);
const reduce = useReducedMotion();
return (
<div className={cn("group relative w-full", className)}>
<LockKeyhole
size={15}
className="pointer-events-none absolute left-3 top-1/2 z-10 -translate-y-1/2 text-muted-foreground transition-colors group-focus-within:text-primary"
/>
<Input
aria-label="Password"
autoComplete="current-password"
{...props}
type={visible ? "text" : "password"}
className="px-10"
/>
<button
type="button"
disabled={props.disabled}
aria-label={visible ? "Hide password" : "Show password"}
aria-pressed={visible}
onMouseDown={(e) => e.preventDefault()}
onClick={() => setVisible((v) => !v)}
className="absolute right-1 top-1 grid size-8 place-items-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground"
>
<AnimatePresence mode="wait" initial={false}>
<motion.span
key={String(visible)}
initial={{
opacity: 0,
rotate: reduce ? 0 : -35,
scale: reduce ? 1 : 0.7,
}}
animate={{ opacity: 1, rotate: 0, scale: 1 }}
exit={{
opacity: 0,
rotate: reduce ? 0 : 35,
scale: reduce ? 1 : 0.7,
}}
transition={{ duration: reduce ? 0 : 0.12 }}
>
{visible ? <EyeOff size={16} /> : <Eye size={16} />}
</motion.span>
</AnimatePresence>
</button>
</div>
);
}
registry/ui/input.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
export function Input({ className, ...props }: React.ComponentProps<"input">) {
return (
<input
className={cn(
"block h-10 w-full min-w-0 rounded-lg border border-border bg-background px-3 text-sm leading-normal shadow-[0_1px_2px_#00000004] transition-[border-color,box-shadow] placeholder:text-muted-foreground/75 hover:border-foreground/25 focus:border-primary focus:outline-none focus:ring-3 focus:ring-primary/10 aria-invalid:border-danger aria-invalid:ring-danger/10 disabled:cursor-not-allowed disabled:bg-muted/50 disabled:opacity-50",
className,
)}
{...props}
/>
);
}
registry/ui/utils.ts
Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
return twMerge(clsx(values));
}
Dependencies
lucide-react@0.577.0 · motion@13.2.0 · clsx@2.1.1 · tailwind-merge@3.5.0
Accessibility & behaviour
Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.
Read the accessibility and performance guide →