Skip to content
WunderUI

Password Requirement

Free

One password rule in a checklist that turns green once the password meets it.

npx wunderui-cli add password-requirement

Playground

  • At least 8 characters, met
  • At least one number, met
  • Upper and lower case letters, not met
  • At least one symbol, not met

Installation

bash
npx wunderui-cli add password-requirement

Writes the source into your project with its dependencies and, on first use, the styles - see Installation.

Then import what you need:

tsx
import { PasswordRequirement } from "@/components/blocks/auth"

Then use it:

tsx
import { PasswordRequirement } from "@wunderui/react"

export function Rules({ password }: { password: string }) {
  const long = password.length >= 8
  return (
    <ul aria-label="Password requirements" className="flex flex-col gap-1.5">
      <PasswordRequirement met={long}>
        At least 8 characters
        <span className="sr-only">{long ? ", met" : ", not met"}</span>
      </PasswordRequirement>
    </ul>
  )
}

Expected result: You see a grey circle with the text At least 8 characters. Pass a password of eight or more characters and the circle turns into a green check.

When to use

Use Password Requirement for

  • The rules of a new password on a sign-up or a reset form, checked as the person types
  • Any short list of conditions that a typed value has to meet, such as a username or a workspace address
  • A list that must stay visible next to the field, so the person sees what is missing before they submit

Use something else for

  • Password Strength for one overall result of how strong a password is, as a meter and a word
  • Alert for an error after a submit, written as a sentence with what to do
  • Checkbox for a list that people tick themselves

State

A met rule shows a green check and the label in the secondary text colour, an unmet rule an empty circle and a tertiary label. The component tests nothing: you pass the result.

  • At least 8 characters, not met

Content

The children are the label, and a long label wraps and is never cut. The icon is centred on the label by default; add items-start to keep it beside the first line.

  • At least 8 characters, not met

Rules

The rules are yours: write each as a label and a test and pass the result. Put them in a named list with a hidden word for the state, because icon and colour are not read aloud.

  • At least 8 characters, met
  • At least one number, not met
  • Upper and lower case letters, not met

1 of 3 requirements met

Behavior and motion

What the component renders and what it leaves to the page.

Display only
PasswordRequirement shows a result; it does not test a password, hold state or fire events. You compute met from the value and pass it, and the row changes on the next render.
States
When met is true the icon is a green check in a circle and the label uses the secondary colour. When false the icon is an empty circle and the label is tertiary.
Semantics
The row is an li, so the list counts the rules. The icon is hidden and the component adds no state text, so a screen reader reads the label only, unless you add a hidden met or not met.
Announcing changes
A row that changes colour is not announced. Put a status line with the count of met rules near the list: it is spoken when the number changes, not on every key press.
Not focusable
The row is not interactive: no focus, no hover state, not a tab stop. The field it describes is the control.
Long labels
The label wraps and is never cut, and the icon is centred on the whole label, so on two lines it sits between them. Align items to the start in the class to keep it beside the first line.
Sample values
Use obviously made-up passwords in examples and tests, such as correct-horse-battery. The demos run on local state and send nothing.
Dark mode
It uses the theme tokens for the text and the success colour, so it follows the theme.
Motion
None. The icon and the colour change at once when met changes; nothing fades or moves.
Reduced motion
There is no motion, so reduced motion changes nothing.

Anatomy

The figure shows one requirement that is met. In the DOM it is an li, so it always sits in a ul or ol that you provide.

  • At least 8 characters, met
  • data-slot="password-requirement"

    An li in a 12 px flex row with 8 px between icon and label, carrying a met data attribute when the rule is met. It renders no list, so put it inside a ul or ol.

  • A 16 px Lucide icon: a check in a circle in the success colour when the rule is met, an empty circle when it is not. It is hidden from assistive technology.

  • The rule text, in the secondary colour when met and the tertiary colour when not. Add a visually hidden word for the state, such as met, so a screen reader reads it.

Best practices

  • Do

    Put the requirements in a ul with an aria-label such as Password requirements. The component is an li, and a list tells a screen reader how many rules there are.

  • Do

    Add a hidden word after the label for the state, such as met or not met, in a screen-reader-only span. Without it the state is shown by icon and colour only, which a screen reader does not read.

  • Do

    Run every rule on each change and pass the result as met. Keep the rules in one array, so the list and the check that enables the submit button never disagree.

  • Do

    Say the total in a status line next to the list, such as 3 of 4 requirements met. It changes only when the count does, so a screen reader announces progress without reading the list on every key.

  • Do

    Point the password field at the list with aria-describedby, so the rules are read when the field gets focus.

  • Don’t

    Don't rely on the green icon alone to show a result, since people who cannot see colour miss it and the unmet circle is not an error. Keep the text and the hidden state word.

  • Don’t

    Don't show an unmet rule as an error before the person has typed. An empty field with every circle empty is the starting point, not a failure.

  • Don’t

    Don't use it for a checklist of tasks: it is a rule that a value passes or fails. Use Checklist Task for steps someone completes.

API reference

One table: PasswordRequirement is a plain component, so it lists every prop. It does not pass other props on to its li.

An li in a 12 px flex row with 8 px between icon and label, carrying a met data attribute when the rule is met. It renders no list, so put it inside a ul or ol.

PropTypeDefaultDescription
met requiredboolean—Whether the password meets the rule. Required. shows the green check, the secondary text colour and ; shows the empty circle and the tertiary colour.
children requiredReactNode—The label of the rule, as text or any content. Add a visually hidden word for the state after it so a screen reader hears whether the rule is met.
classNamestring—Extra classes for the row, merged after its own. Use them for on a label that wraps or a different text size.

Notes for AI

Give your coding assistant the Markdown reference instead of screenshots.

MCPget_component("password-requirement")
Installnpx wunderui-cli add password-requirement

The full library index for assistants is at /llms.txt.