Open this example in the interactive library
Live preview
Source code
// components/PasswordRevealToggle.tsx
import { useState } from "react";
export default function PasswordRevealToggle({
label = "Email",
}: { label?: string } = {}) {
const [show, set] = useState(false);
return (
<div>
<label>
Password
<input autoComplete="current-password" type={show ? "text" : "password"} />
</label>
<button type="button" aria-pressed={show} onClick={() => set(!show)}>
Show password
</button>
</div>
);
}
