feat(web): 登录/改密/成员表单加密码可见切换
This commit is contained in:
@@ -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>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user