Yugen UI

PasswordInput

PasswordInput is a password field with a show / hide button, a Caps Lock note and an optional strength meter.

An Input with type="password" and a show / hide button (a toggle button with aria-pressed; clicking it keeps focus in the field). When Caps Lock is on while typing, a note appears under the field and is read through a live region. strength adds a four-step meter (Weak, Fair, Good, Strong) with a text label, so it doesn't rely on color; getPasswordStrength scores by length and character variety, or pass your own scoring function. Takes every Input prop and works inside <Field>; built-in strings change through messages.passwordInput.

Import

Install from npm, copy the source into your project with @yugen-ui/cli or the shadcn CLI, or import directly when working in this repo.

TSX
// npm install yugen-uiimport { PasswordInput, getPasswordStrength, type PasswordStrength } from "yugen-ui";

Variants

Each tile is a standalone example: hover to copy, or press Code to see the source.

12 characters or more, with numbers and symbols

Strength meter

strength uses getPasswordStrength; the level is announced when it changes.

Your own scoring

Return 0–4 from your own rules; capsLockWarning={false} turns the Caps Lock note off.

Size, appearance & disabled

As on Input; defaultVisible shows the password from the start.

Usage

Do
  • Set autoComplete: "current-password" to sign in, "new-password" to create one, so password managers can fill and suggest.
  • Put the password rules in the Field hint, before people start typing.
  • Check the real strength on the server; the meter is a quick hint.
Don't
  • Don't block pasting into a password field. People using a password manager need it.
  • Don't rely on the meter's color alone; keep the text label.

Props

Prop · TypeDefaultDescription
visible / defaultVisiblebooleanDefault: falseWhether the password shows as text (controlled / uncontrolled).
onVisibleChange(visible: boolean) => voidDefault: —Called when the show / hide button is pressed.
capsLockWarningbooleanDefault: trueShows a note when Caps Lock is on while typing.
strengthboolean | (password: string) => PasswordStrengthDefault: —Strength meter: true uses getPasswordStrength, or pass a function that returns 0–4.
getPasswordStrength(password: string) => PasswordStrengthDefault: —0 empty · 1 weak · 2 fair · 3 good · 4 strong, by length and character variety.
value / defaultValue / onChange—Default: —As on Input.
label / hint / validationState / validationMessage—Default: —As on Input; or wrap it in <Field>.
size / appearance / contentBefore / contentAfter—Default: —As on Input; contentAfter sits after the show / hide button.
rootClassNamestringDefault: —Class for the outer wrapper (field, meter, note).
refRef<HTMLInputElement>Default: —Points to the <input> element.

Messages

Text built into the component: labels, aria-labels, screen reader announcements.

English by default. Change it with the messages prop of YugenProvider, by the namespace below; messagesVi has the Vietnamese set. See Interface language.

messages.passwordInput

Key · TypeDefault (English)messagesVi
showstring

aria-label nút hiện / ẩn mật khẩu (nút bật tắt, aria-pressed cho biết đang hiện).

Default (English)"Show password"messagesVi"Hiện mật khẩu"
capsLockstring

Nhắc khi Caps Lock đang bật lúc gõ.

Default (English)"Caps Lock is on"messagesVi"Caps Lock đang bật"
strengthstring

Nhãn của thước đo độ mạnh.

Default (English)"Strength"messagesVi"Độ mạnh"
weakstring

Bốn mức của getPasswordStrength (1 → 4).

Default (English)"Weak"messagesVi"Yếu"
fairstringDefault (English)"Fair"messagesVi"Trung bình"
goodstringDefault (English)"Good"messagesVi"Khá"
strongstringDefault (English)"Strong"messagesVi"Mạnh"