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:
@@ -3,6 +3,7 @@
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
import { PasswordInput } from "@/components/PasswordInput";
|
||||
import { Turnstile } from "@/components/Turnstile";
|
||||
import { ApiError, api, errorText } from "@/lib/api";
|
||||
|
||||
@@ -151,10 +152,9 @@ export function PasswordLogin({
|
||||
Elfelejtett jelszó?
|
||||
</button>
|
||||
</div>
|
||||
<input
|
||||
<PasswordInput
|
||||
id="pw-password"
|
||||
className="inp"
|
||||
type="password"
|
||||
required
|
||||
autoComplete="current-password"
|
||||
value={password}
|
||||
|
||||
@@ -1803,3 +1803,14 @@ span.tarot-fan-card { cursor: default; }
|
||||
.ask-forum-card { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
|
||||
.ask-forum-body { display: flex; flex-direction: column; gap: 12px; }
|
||||
.ask-forum-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
|
||||
|
||||
/* Password fields with an eye button (PasswordInput). */
|
||||
.pw-input { position: relative; display: block; }
|
||||
.pw-input .inp { padding-right: 48px; }
|
||||
.pw-input input::-ms-reveal, .pw-input input::-ms-clear { display: none; }
|
||||
.pw-eye {
|
||||
position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px;
|
||||
display: grid; place-items: center; border: 0; border-radius: 8px; background: none; color: #8a93ab; cursor: pointer;
|
||||
}
|
||||
.pw-eye:hover, .pw-eye:focus-visible { color: var(--gold); }
|
||||
.pw-eye svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
|
||||
|
||||
@@ -4,6 +4,7 @@ import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
import { PasswordInput } from "@/components/PasswordInput";
|
||||
import { ApiError, api, errorText } from "@/lib/api";
|
||||
|
||||
/** Sets the password with the e-mailed link's token; logs in on success. */
|
||||
@@ -55,10 +56,9 @@ export function SetPasswordForm({ token, minLength }: { token: string; minLength
|
||||
<form className="field" onSubmit={submit} style={{ gap: 14 }}>
|
||||
<div className="field">
|
||||
<label htmlFor="new-password">Új jelszó</label>
|
||||
<input
|
||||
<PasswordInput
|
||||
id="new-password"
|
||||
className="inp"
|
||||
type="password"
|
||||
required
|
||||
minLength={minLength}
|
||||
autoComplete="new-password"
|
||||
@@ -69,10 +69,9 @@ export function SetPasswordForm({ token, minLength }: { token: string; minLength
|
||||
</div>
|
||||
<div className="field">
|
||||
<label htmlFor="new-password-again">Új jelszó még egyszer</label>
|
||||
<input
|
||||
<PasswordInput
|
||||
id="new-password-again"
|
||||
className="inp"
|
||||
type="password"
|
||||
required
|
||||
autoComplete="new-password"
|
||||
value={again}
|
||||
|
||||
@@ -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