Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Forms

PasswordInput

Free17.1 KB gzipped

A password field built on Input, with a show/hide toggle, a Caps Lock warning, an optional strength meter, and an optional requirements checklist.

Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Enter, Space · Full report

Import

tsx
import { PasswordInput } from "@vjdesigns/vjdesigns-ui";

Importing only PasswordInput adds about 17.1 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.

Examples

Basic

A show/hide toggle and a Caps Lock warning are built in.

tsx
import { Field, PasswordInput } from "@vjdesigns/vjdesigns-ui";

export function Basic() {
  return (
    <div style={{ width: "100%", maxWidth: "22rem" }}>
      <Field label="Password">
        <PasswordInput autoComplete="current-password" />
      </Field>
    </div>
  );
}

New password

strength shows a meter, and requirements lists rules that tick off as they're met. Changes are announced politely.

Your password needs:

  • At least 12 characters: Not met
  • A number: Not met
  • Upper and lower case letters: Not met
tsx
import { Field, PasswordInput } from "@vjdesigns/vjdesigns-ui";

export function NewPassword() {
  return (
    <div style={{ width: "100%", maxWidth: "22rem" }}>
      <Field label="New password">
        <PasswordInput
          autoComplete="new-password"
          strength
          requirements={[
            { id: "length", label: "At least 12 characters", test: (p) => p.length >= 12 },
            { id: "number", label: "A number", test: (p) => /\d/.test(p) },
            { id: "case", label: "Upper and lower case letters", test: (p) => /[a-z]/.test(p) && /[A-Z]/.test(p) },
          ]}
        />
      </Field>
    </div>
  );
}

Accessibility

requirements shows a live checklist, and after typing pauses one polite summary of the strength and the rules met is announced, instead of every keystroke. capsLockWarning warns while Caps Lock is on, and the show/hide toggle is a real button named by showLabel / hideLabel.

Your password needs:

  • At least 12 characters: Not met
  • Contains a number: Not met
tsx
import { Field, PasswordInput } from "@vjdesigns/vjdesigns-ui";

export function Accessibility() {
  return (
    <div style={{ width: "100%", maxWidth: "22rem" }}>
      <Field label="Create a password">
        <PasswordInput
          autoComplete="new-password"
          capsLockWarning
          strength
          requirements={[
            { id: "length", label: "At least 12 characters", test: (p) => p.length >= 12 },
            { id: "number", label: "Contains a number", test: (p) => /\d/.test(p) },
          ]}
          showLabel="Show password"
          hideLabel="Hide password"
        />
      </Field>
    </div>
  );
}

Translated

The toggle's name, the Caps Lock warning, the strength labels and the announcements come from the locale (French here). The rule labels are your own text.

Votre mot de passe doit contenir :

  • Au moins 12 caractères: Non rempli
tsx
import { Field, PasswordInput, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import fr from "@vjdesigns/vjdesigns-ui/locales/fr";

export function Translated() {
  return (
    <LocaleProvider locale="fr" messages={fr}>
      <div style={{ width: "100%", maxWidth: "22rem" }}>
        <Field label="Mot de passe">
          <PasswordInput
            autoComplete="new-password"
            strength
            requirements={[{ id: "length", label: "Au moins 12 caractères", test: (p) => p.length >= 12 }]}
          />
        </Field>
      </div>
    </LocaleProvider>
  );
}

Right to left

The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.

Basic

tsx
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";

// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
  <Basic />
</LocaleProvider>

Usage notes

Accepts every Input prop except type. Defaults to autoComplete="current-password"; use autoComplete="new-password" on sign-up and change-password forms so password managers offer to generate and save a password.

WCAG 2.2 SC 3.3.8 (Accessible Authentication): this component never blocks paste, drag-and-drop, or password-manager autofill, and it doesn't add cognitive tests. Don't add onPaste={e => e.preventDefault()} or a "retype without pasting" rule on top of it.

tsx
<Field label="Password">
  <PasswordInput autoComplete="new-password" strength requirements={rules} />
</Field>

API reference

PasswordInput

PasswordInput props
PropTypeDefault
visible

Shows the password as plain text (controlled).

boolean—
defaultVisible

Initial visibility when uncontrolled.

booleanfalse
onVisibleChange

Called with the new visibility when the toggle is pressed (or the form submits while visible).

(visible: boolean) => void—
visibilityToggle

Renders the show/hide toggle button.

booleantrue
showLabel

Accessible name of the toggle. By default the name stays the same and aria-pressed carries the state ("Show password, toggle button, pressed"), as the WAI-ARIA button pattern recommends.

string"Show password"
hideLabel

Optional name to use while the password is visible (e.g. "Hide password"). When set, the name switches with the state and aria-pressed is omitted, since a changing name and a pressed state together would contradict each other ("Hide password, pressed").

string—
capsLockWarning

Show a warning while Caps Lock is on and the field has focus.

booleantrue
capsLockText

Text of the Caps Lock warning.

ReactNode"Caps Lock is on"
strength

Strength meter. Pass a score (0 to 4) you compute yourself, a scorer function (password) => ({ score, label? }), or true to use the built-in scorePassword heuristic. Omit to hide the meter.

number | PasswordStrengthScorer | true—
strengthLabels

Labels for scores 0 to 4.

PasswordStrengthLabels["Too weak", "Weak", "Fair", "Good", "Strong"]
strengthPrefix

Text before the strength label.

string"Strength:"
requirements

Rules shown as a live checklist under the field.

PasswordRequirement[]—
requirementsLabel

Heading above the checklist.

ReactNode"Your password needs:"
metText

Screen-reader text for a met rule.

string"Met"
notMetText

Screen-reader text for an unmet rule.

string"Not met"
formatAnnouncement

Builds the polite summary announced after typing pauses, from the strength label (if any) and the met/total rule counts.

(info: { strengthLabel?: string; met: number; total: number; }) => string—
announceDelay

Pause after typing before strength/requirement changes are announced, in ms.

number900
fieldClassName

Class name for the Input's field wrapper. className goes to the outer root.

string—
ref

Ref to the <input> element.

Ref<HTMLInputElement>—
startIcon

Decorative icon before the text. Hidden from assistive technology.

ReactNode—
endIcon

Decorative icon after the text. Hidden from assistive technology.

ReactNode—
loading

Shows a decorative spinner at the end and sets aria-busy on the input. Announce the outcome of the async work elsewhere (e.g. a status message).

booleanfalse
fullWidth

Stretches the field to fill its container.

booleantrue
variant

Visual style.

"outline""filled""outline"
size

Control height, padding, and type size. Inherits from a surrounding Field when not set.

"sm""md""lg""md"
radius

Corner rounding. When omitted, uses --field-radius. Use pill for search bars.

"none""xs""sm""md""lg""xl""2xl""pill"—
onValueChange

Called with the new value on every change (typing, pasting, clearing).

(value: string) => void—
invalid

Marks the value as invalid: sets aria-invalid and a danger border. Pair it with a visible error message (a Field does this for you). Inherits from a surrounding Field.

booleanfalse
clearable

Shows a clear button (aria-label="Clear") while the input has a value. Clearing fires a native-like change (so onChange runs), calls onValueChange(""), and moves focus back to the input. Hidden while disabled or read-only.

booleanfalse
clearLabel

Accessible name of the clear button.

string"Clear"
inputClassName

Class name for the <input> element. className goes to the wrapper.

string—
onClear

Called after the clear button empties the field (after onChange/onValueChange).

() => void—
startAddon

Static content attached to the start edge, such as "https://" or a currency symbol. Text addons are announced as part of the input's description (aria-describedby).

ReactNode—
endAddon

Static content attached to the end edge, such as ".com" or a unit ("kg"). Text addons are announced as part of the input's description.

ReactNode—
startElement

Interactive content inside the start edge (for example an IconButton with size="sm" and variant="ghost"). Stays in the tab order; give it its own accessible name.

ReactNode—
endElement

Interactive content inside the end edge (for example a copy or show-password IconButton). Stays in the tab order; give it its own accessible name.

ReactNode—
htmlSize

The native size attribute (visible width in characters). Mostly useful with fullWidth={false}.

number—

Also accepts standard HTML attributes, plus className, style and ref.

See what changed in each version in the Changelog.

Accessibility report

PasswordInput targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.

axe-core audit (live)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

37 passed · 0 failed · 28 not applicable · 10 to check by hand

Dark mode

Score 100

37 passed · 0 failed · 28 not applicable · 10 to check by hand

Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.

Built-in behavior

Keyboard

Keyboard
KeyAction
TabMoves focus into the field.
TypingEdits the text, with the browser's usual caret and selection keys.
EnterSpaceOn the show / hide button: toggles visibility.

Roles and states

Roles and states
ElementRoleStates and properties
<input type="password">none (password field)aria-describedby → hint, requirements and error
Show / hide buttonbuttonaria-pressed, aria-label, aria-controls → input
RequirementslistEach requirement says whether it's met in text
StrengthstatusAnnounced politely

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck.2.1.1 (A), 2.1.2 (A)
FocusFocus moves in a logical order, is always visible, and isn't hidden behind sticky headers.2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA)
Screen readersNames, roles and states are announced correctly, and status changes are announced without moving focus.1.3.1 (A), 4.1.2 (A), 4.1.3 (AA)
ColorMeaning never depends on color alone; your own colors meet contrast in both modes.1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA)
Zoom and reflowAt 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed.1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA)
Pointer targetsClick and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap.2.5.8 (AA), 2.5.5 (AAA)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)