Password
A labelled password input with a reveal toggle and an optional on-device strength meter and requirement checklist.
import { PasswordInput } from '@uthereal/ui/password-input'Password input playground
Overview
PasswordInput renders a labelled native password field on Zag's password-input machine with a reveal toggle button. Set showStrength to turn the field into a new-password input with a four-segment strength meter, a strength label, and a live requirement checklist.
| Aspect | Sign-in (showStrength: false) | Registration (showStrength: true) |
|---|---|---|
Default autoComplete | current-password | new-password |
| Shell and toggle | Standard field shell with a 30px toggle pressing to 0.96 | 16px start inset, 34px toggle pressing to 0.94, 16px text on coarse pointers |
| Toggle accessible name | Switches between showPasswordLabel and hidePasswordLabel | Stays showPasswordLabel with aria-pressed and aria-controls |
| Meter and checklist | Hidden | Four-segment meter, strength word, checklist with rolling remaining counts, role="status" updates |
| Error transition | Message words exit over 180ms | Line swap plus a single horizontal shake on each new error |
Strength scoring runs on the device and sends no data over the network. Password values never enter component configuration (defaultValue is omitted by design) or persisted host state; your application owns the string and validates it.
Usage
'use client'
import { useState } from 'react'
import {
PasswordInput,
type PasswordStrengthResult,
} from '@uthereal/ui/password-input'
export function CreatePassword() {
const [password, setPassword] = useState('')
const [strength, setStrength] = useState<PasswordStrengthResult | null>(null)
return (
<PasswordInput
label="New password"
showStrength
autoComplete="new-password"
required
value={password}
onValueChange={(next, result) => {
setPassword(next)
setStrength(result)
}}
error={
password && strength && strength.level < 3
? 'Choose a stronger password.'
: undefined
}
/>
)
}Omit value for an uncontrolled field that starts empty. onValueChange runs in both controlled and uncontrolled modes with the current string and its PasswordStrengthResult. Import scorePassword, meetsRequirement, remainingCharacters, and countCharacters from @uthereal/ui/password-input to run the same scoring rules during form submission or server validation.
Examples
New password with strength meter
Enable showStrength when creating or changing a password. Render the default four-rule checklist (12 characters, mixed case, number, symbol) for full guidance, or set showRequirements={false} to display the compact meter alone beside description copy. Pass custom requirements and shortLength when your policy differs.
- At least 12 characters, not met
- Upper and lowercase letters, not met
- At least one number, not met
- At least one symbol, not met
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
label | stringDefault: "Password" | Visible label and accessible name. Name the information asked for, in sentence case. |
hideLabel | booleanDefault: false | Hide the label visually when the context already names the field. It is still announced. |
description | string— | Supporting text below the field, announced with it. Use it for format hints and constraints. |
error | string— | Validation message from your application. Setting it marks the field invalid; the message is linked to the field and announced politely. |
required | booleanDefault: false | Marks the field as required for assistive technology and shows an indicator. Your application validates the value. |
readOnly | booleanDefault: false | The value can be focused, selected, and copied, but not edited. It is still submitted with a form. |
disabled | booleanDefault: false | Unavailable and removed from the tab order. A disabled field is not submitted with a form. |
name | string— | Native form field name, submitted with the value in a form. |
placeholder | string— | Text shown while the field is empty, e.g. "At least 12 characters". It never replaces the label. |
autoComplete | current-password | new-passwordDefault: "current-password" | current-password for signing in, new-password when creating or changing one, so password managers fill or suggest correctly. With showStrength it defaults to new-password. |
defaultVisible | booleanDefault: false | Show the characters initially. Later argument edits do not reset an existing instance; use revealed and onRevealedChange to control it. |
showPasswordLabel | stringDefault: "Show password" | Accessible name of the reveal button while the characters are hidden. |
hidePasswordLabel | stringDefault: "Hide password" | Accessible name of the reveal button while the characters are shown. |
maxLength | integer— | Maximum number of characters the user can type. Omit it for no limit. |
icon | IconName— | Decorative icon before the text, e.g. lock. Any name from the Icons page. |
showStrength | booleanDefault: false | Add the strength meter, strength word and requirement checklist, turning the field into a new-password field with a roomier shell, new-password autofill and a shake on a new error. Show it when the user creates or changes a password. |
showRequirements | booleanDefault: true | Show the checklist below the meter (with showStrength). Hide it when the description already lists the rules. |
requirements | PasswordRequirement[]Default: [{"id":"length","kind":"minLength","min":12,"label":"At least 12 characters"},{"id":"case","kind":"mixedCase","label":"Upper and lowercase letters"},{"id":"number","kind":"number","label":"At least one number"},{"id":"symbol","kind":"symbol","label":"At least one symbol"}] | The checklist, in order. Each has an id, a visible label and a built-in test: minLength (with min), lowercase, uppercase, mixedCase, number, or symbol. Strength is the share of requirements met, spread over four steps (weak, fair, good, strong); an unmet length requirement shows how many characters remain. |
shortLength | integerDefault: 8 | Below this many characters (counted as people count them, so an emoji is one) the meter holds at its first step and reads too short, however varied the password is. |
levels | PasswordInputLevels— | The strength words: empty, tooShort, weak, fair, good, and strong. Translate them with the rest of your interface. |
strengthLabels | PasswordInputStrengthLabels— | Accessible names of the meter and the checklist, the words read after each requirement (met, not met), the remaining-characters count beside an unmet length requirement ({count}), and the summary announced after each change ({strength}, {met}, {total}). |
variant | outline | soft | ghostDefault: "outline" | Field surface: outline for forms, soft on busy surfaces, ghost for inline editing without a border. |
size | sm | md | lgDefault: "md" | Field height and text size: 32, 36, or 46 pixels. Matches the button and dropdown trigger of the same size. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | PasswordInputTheme— | Color mode, accent, and semantic tokens, including the meter thickness. See Theming for all keys and defaults. |
motion | none | subtle | expressiveDefault: "subtle" | Hover and focus colors, the drawn eye slash, the text resolving on reveal, the toggle press, and the message rows; with showStrength: a shake on a new error, segments sliding in as a wave, the strength word rising or dropping with the direction of change, ticks drawing in and remaining counts rolling. Reduced motion fades; none makes every change immediate. |
motionOptions | PasswordInputMotionOptions— | How the meter segments slide to a new strength (the value family; smooth spring by default). Durations are milliseconds. |
dir | ltr | rtl— | Reading direction. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
value, onValueChange | Controlled password string and (value, strength) callback. Fires in both modes. |
revealed, onRevealedChange | Controlled reveal visibility; omit to initialize from defaultVisible. |
countCharacters | Custom character counter for shortLength and minLength (defaults to code points; pass s => s.length for UTF-16). |
customRules | Extra { id, label, test, remaining? } checklist rules appended after requirements; never serialized. |
renderIcon(name, context) | Custom renderer for the leading icon (slot: 'icon') and checklist marks (slot: 'met' | 'unmet'). The reveal toggle keeps the animated eye. |
ref | Ref to the native <input> element. |
preset | Application defaults (such as translated labels and strength words), overridden by props. |
tokens | CSS custom properties (--ui-*) applied after the typed theme. |
className, style | Applied to the root field element, which carries the resolved tokens. |
| Native attributes | Forwarded to <input> (onChange, onBlur, onKeyDown, autoFocus, aria-*). |
Keyboard & accessibility
| Key | Interaction |
|---|---|
Tab | Moves focus to the password input, then to the reveal toggle button. |
Enter, Space | On the reveal toggle button: shows or hides the password characters. |
The reveal toggle is a native <button type="button"> in the tab order with aria-pressed. In sign-in mode its label switches between showPasswordLabel and hidePasswordLabel; with showStrength it keeps showPasswordLabel and references the input via aria-controls. Submitting or resetting a surrounding <form> masks the characters again, and disabled or read-only fields cannot be revealed.
With showStrength, the bar exposes role="meter" with aria-valuemin={0}, aria-valuemax={4}, aria-valuenow, and aria-valuetext set to the active word in levels. When showRequirements is enabled, the checklist <ul> joins the input's aria-describedby after any description or error, each rule appends a visually hidden met or not-met status, and a polite role="status" region announces changes while the input is non-empty. Spell checking, auto-correct, and auto-capitalization stay off. All layout spacing and segment directions adapt to dir="rtl", and forced-colors: active preserves outlines, tracks, fills, and checklist marks using system colors.
Motion and theming
- Reveal toggle: a single eye SVG draws a masked slash across the iris (
240ms), the input text resolves from a light blur on each toggle after mount, and the button presses to0.96(0.94withshowStrength) over100msbefore releasing on the CSS spring. - Strength meter: four segments slide into clipped pill tracks on the smooth spring in a staggered wave (
50msper segment filling,30msemptying), changing tone acrossdanger,warning, andsuccess. - Strength word and counts: the strength word rises when strength improves and drops when it falls; unmet
minLengthrules display rolling remaining-character counters. - Checklist marks and errors: met rules pop a tinted ring on the snappy spring and draw a checkmark stroke; in strength mode, each new
errorshakes the control shell once on a damped velocity spring. - Reduced motion:
prefers-reduced-motion: reducedisables travel, scale, blur-resolve, slash draw, and error shake while keeping120msopacity fades for text swaps.motion="none"makes all updates immediate (0ms).
theme accepts the core and control token groups, plus borderStrong, success, warning, and the component token thickness (--ui-password-input-thickness, defaulting to 4px at md/lg and 3px at sm).
Composition
PasswordInput is a leaf component in the fields namespace with an empty persisted state (state: {}). By design, its schema has no defaultValue and its value is never written to json-render state, ensuring secret credentials never enter agent prompts, tool arguments, or serialized UI snapshots. Only non-secret reveal visibility (onRevealedChange) is exposed as a UI event; the host application captures and submits the password directly. See Building with agents.
{
"type": "PasswordInput",
"props": {
"label": "New password",
"showStrength": true,
"autoComplete": "new-password",
"required": true
},
"children": []
}