feat(web): 登录/改密/成员表单加密码可见切换

This commit is contained in:
姚章浩
2026-09-15 11:50:21 +08:00
parent 83d0347ca7
commit f8cef26f4a
5 changed files with 80 additions and 5 deletions
+29
View File
@@ -0,0 +1,29 @@
import { useState } from 'react'
import type { InputHTMLAttributes } from 'react'
// PasswordInput renders a password field with an inline visibility toggle so
// users can verify what they typed before submitting. The toggle is a
// presentation-only button (type=button) nested in a relative wrapper; it
// never submits the surrounding form.
interface PasswordInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> {
autoComplete: string
initiallyRevealed?: boolean
}
export function PasswordInput({ autoComplete, initiallyRevealed = false, ...inputProps }: PasswordInputProps) {
const [revealed, setRevealed] = useState(initiallyRevealed)
return (
<span className="password-field">
<input {...inputProps} type={revealed ? 'text' : 'password'} autoComplete={autoComplete} />
<button
type="button"
className="password-toggle"
aria-label={revealed ? '隐藏密码' : '显示密码'}
aria-pressed={revealed}
onClick={() => setRevealed((value) => !value)}
>
{revealed ? '隐藏' : '显示'}
</button>
</span>
)
}