Forms
PasswordInput
Free17.1 KB gzippedA 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
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.
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
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
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
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
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.
<Field label="Password">
<PasswordInput autoComplete="new-password" strength requirements={rules} />
</Field>
API reference
PasswordInput
| Prop | Type | Default |
|---|---|---|
visibleShows the password as plain text (controlled). | boolean | — |
defaultVisibleInitial visibility when uncontrolled. | boolean | false |
onVisibleChangeCalled with the new visibility when the toggle is pressed (or the form submits while visible). | (visible: boolean) => void | — |
visibilityToggleRenders the show/hide toggle button. | boolean | true |
showLabelAccessible name of the toggle. By default the name stays the same and | string | "Show password" |
hideLabelOptional name to use while the password is visible (e.g. "Hide password"). When set, the name switches with the state and | string | — |
capsLockWarningShow a warning while Caps Lock is on and the field has focus. | boolean | true |
capsLockTextText of the Caps Lock warning. | ReactNode | "Caps Lock is on" |
strengthStrength meter. Pass a score (0 to 4) you compute yourself, a scorer function | number | PasswordStrengthScorer | true | — |
strengthLabelsLabels for scores 0 to 4. | PasswordStrengthLabels | ["Too weak", "Weak", "Fair", "Good", "Strong"] |
strengthPrefixText before the strength label. | string | "Strength:" |
requirementsRules shown as a live checklist under the field. | PasswordRequirement[] | — |
requirementsLabelHeading above the checklist. | ReactNode | "Your password needs:" |
metTextScreen-reader text for a met rule. | string | "Met" |
notMetTextScreen-reader text for an unmet rule. | string | "Not met" |
formatAnnouncementBuilds 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 | — |
announceDelayPause after typing before strength/requirement changes are announced, in ms. | number | 900 |
fieldClassNameClass name for the Input's field wrapper. | string | — |
refRef to the | Ref<HTMLInputElement> | — |
startIconDecorative icon before the text. Hidden from assistive technology. | ReactNode | — |
endIconDecorative icon after the text. Hidden from assistive technology. | ReactNode | — |
loadingShows a decorative spinner at the end and sets | boolean | false |
fullWidthStretches the field to fill its container. | boolean | true |
variantVisual style. | "outline""filled" | "outline" |
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | — |
onValueChangeCalled with the new value on every change (typing, pasting, clearing). | (value: string) => void | — |
invalidMarks the value as invalid: sets | boolean | false |
clearableShows a clear button ( | boolean | false |
clearLabelAccessible name of the clear button. | string | "Clear" |
inputClassNameClass name for the | string | — |
onClearCalled after the clear button empties the field (after | () => void | — |
startAddonStatic content attached to the start edge, such as | ReactNode | — |
endAddonStatic content attached to the end edge, such as | ReactNode | — |
startElementInteractive content inside the start edge (for example an | ReactNode | — |
endElementInteractive content inside the end edge (for example a copy or show-password | ReactNode | — |
htmlSizeThe native | 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)
Checking the examples above…
Lighthouse audit
Light mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Dark mode
Score 10037 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
| Key | Action |
|---|---|
| Tab | Moves focus into the field. |
| Typing | Edits the text, with the browser's usual caret and selection keys. |
| EnterSpace | On the show / hide button: toggles visibility. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
<input type="password"> | none (password field) | aria-describedby → hint, requirements and error |
| Show / hide button | button | aria-pressed, aria-label, aria-controls → input |
| Requirements | list | Each requirement says whether it's met in text |
| Strength | status | Announced politely |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every 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) |
| Focus | Focus 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 readers | Names, 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) |
| Color | Meaning 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 reflow | At 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 targets | Click 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) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |