Password fields with an eye button to show or hide the password
The login form and the new password page (both fields) use PasswordInput: an eye button shows what was typed and hides it again (the caret stays in the field; Edge's own reveal button is hidden so there are not two). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
/**
|
||||
* A password field with an eye button that shows or hides what was typed
|
||||
* (the browser's own reveal button, where there is one, is hidden in CSS).
|
||||
*/
|
||||
export function PasswordInput(props: Omit<React.InputHTMLAttributes<HTMLInputElement>, "type">) {
|
||||
const [shown, setShown] = useState(false);
|
||||
return (
|
||||
<span className="pw-input">
|
||||
<input {...props} type={shown ? "text" : "password"} autoCapitalize="none" autoCorrect="off" spellCheck={false} />
|
||||
<button
|
||||
type="button"
|
||||
className="pw-eye"
|
||||
aria-label={shown ? "Jelszó elrejtése" : "Jelszó megjelenítése"}
|
||||
aria-pressed={shown}
|
||||
aria-controls={props.id}
|
||||
// The caret stays in the field.
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => setShown((s) => !s)}
|
||||
>
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M2.5 12S6 5.5 12 5.5 21.5 12 21.5 12 18 18.5 12 18.5 2.5 12 2.5 12z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
{shown && <path d="M4 20L20 4" />}
|
||||
</svg>
|
||||
</button>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user