UI

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

Loading interactive preview…

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.

AspectSign-in (showStrength: false)Registration (showStrength: true)
Default autoCompletecurrent-passwordnew-password
Shell and toggleStandard field shell with a 30px toggle pressing to 0.9616px start inset, 34px toggle pressing to 0.94, 16px text on coarse pointers
Toggle accessible nameSwitches between showPasswordLabel and hidePasswordLabelStays showPasswordLabel with aria-pressed and aria-controls
Meter and checklistHiddenFour-segment meter, strength word, checklist with rolling remaining counts, role="status" updates
Error transitionMessage words exit over 180msLine 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.

Password strength
  • At least 12 characters, not met
  • Upper and lowercase letters, not met
  • At least one number, not met
  • At least one symbol, not met
Use at least 12 characters with mixed case, a number, and a symbol.
Password strength

API reference

These serializable arguments and defaults come directly from the component schema.

ArgumentType / defaultDescription
labelstringDefault: "Password"Visible label and accessible name. Name the information asked for, in sentence case.
hideLabelbooleanDefault: falseHide the label visually when the context already names the field. It is still announced.
descriptionstring—Supporting text below the field, announced with it. Use it for format hints and constraints.
errorstring—Validation message from your application. Setting it marks the field invalid; the message is linked to the field and announced politely.
requiredbooleanDefault: falseMarks the field as required for assistive technology and shows an indicator. Your application validates the value.
readOnlybooleanDefault: falseThe value can be focused, selected, and copied, but not edited. It is still submitted with a form.
disabledbooleanDefault: falseUnavailable and removed from the tab order. A disabled field is not submitted with a form.
namestring—Native form field name, submitted with the value in a form.
placeholderstring—Text shown while the field is empty, e.g. "At least 12 characters". It never replaces the label.
autoCompletecurrent-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.
defaultVisiblebooleanDefault: falseShow the characters initially. Later argument edits do not reset an existing instance; use revealed and onRevealedChange to control it.
showPasswordLabelstringDefault: "Show password"Accessible name of the reveal button while the characters are hidden.
hidePasswordLabelstringDefault: "Hide password"Accessible name of the reveal button while the characters are shown.
maxLengthinteger—Maximum number of characters the user can type. Omit it for no limit.
iconIconName—Decorative icon before the text, e.g. lock. Any name from the Icons page.
showStrengthbooleanDefault: falseAdd 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.
showRequirementsbooleanDefault: trueShow the checklist below the meter (with showStrength). Hide it when the description already lists the rules.
requirementsPasswordRequirement[]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.
shortLengthintegerDefault: 8Below 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.
levelsPasswordInputLevels—The strength words: empty, tooShort, weak, fair, good, and strong. Translate them with the rest of your interface.
strengthLabelsPasswordInputStrengthLabels—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}).
variantoutline | soft | ghostDefault: "outline"Field surface: outline for forms, soft on busy surfaces, ghost for inline editing without a border.
sizesm | md | lgDefault: "md"Field height and text size: 32, 36, or 46 pixels. Matches the button and dropdown trigger of the same size.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themePasswordInputTheme—Color mode, accent, and semantic tokens, including the meter thickness. See Theming for all keys and defaults.
motionnone | 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.
motionOptionsPasswordInputMotionOptions—How the meter segments slide to a new strength (the value family; smooth spring by default). Durations are milliseconds.
dirltr | rtl—Reading direction. Omit it to inherit the page direction.

React integration

PropPurpose
value, onValueChangeControlled password string and (value, strength) callback. Fires in both modes.
revealed, onRevealedChangeControlled reveal visibility; omit to initialize from defaultVisible.
countCharactersCustom character counter for shortLength and minLength (defaults to code points; pass s => s.length for UTF-16).
customRulesExtra { 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.
refRef to the native <input> element.
presetApplication defaults (such as translated labels and strength words), overridden by props.
tokensCSS custom properties (--ui-*) applied after the typed theme.
className, styleApplied to the root field element, which carries the resolved tokens.
Native attributesForwarded to <input> (onChange, onBlur, onKeyDown, autoFocus, aria-*).

Keyboard & accessibility

KeyInteraction
TabMoves focus to the password input, then to the reveal toggle button.
Enter, SpaceOn 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 to 0.96 (0.94 with showStrength) over 100ms before releasing on the CSS spring.
  • Strength meter: four segments slide into clipped pill tracks on the smooth spring in a staggered wave (50ms per segment filling, 30ms emptying), changing tone across danger, warning, and success.
  • Strength word and counts: the strength word rises when strength improves and drops when it falls; unmet minLength rules 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 error shakes the control shell once on a damped velocity spring.
  • Reduced motion: prefers-reduced-motion: reduce disables travel, scale, blur-resolve, slash draw, and error shake while keeping 120ms opacity 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": []
}

On this page