Components

Password Input

A native password field with a button that shows what’s typed, a Caps Lock hint and a checklist for new passwords. Built on ui-sdk’s Password Input.

Usage

import {
  PasswordInput,
  PasswordInputControl,
  PasswordInputToggle,
} from 'nyctoui/password-input'

<PasswordInput name="password" autoComplete="current-password">
  <PasswordInputControl aria-label="Password" />
  <PasswordInputToggle />
</PasswordInput>

The root draws the field’s box, like InputGroup. Pressing the toggle keeps the caret where it was, and the password hides again when its form submits or the page is left, so the browser offers to save it. Put form options (name, required, disabled) on PasswordInput and input attributes such as placeholder on the control.

Good for

  • The password field on a sign-in page, with a show button.
  • Choosing a new password on sign-up, with a checklist of rules.
  • Changing a password in account security settings.
  • Entering a Wi-Fi or a database password in a setup flow.

Anatomy

<PasswordInput>
  <PasswordInputControl />
  <PasswordInputCapsLock />
  <PasswordInputToggle />
</PasswordInput>
<PasswordRequirements>
  <PasswordRequirement />
</PasswordRequirements>

Examples

Caps Lock

The demo above has a PasswordInputCapsLock before the toggle. Focus the field and press Caps Lock: an arrow appears and is announced. Its space is kept, so the toggle never moves.

New password

On a sign-up or reset form, pass autoComplete="new-password" and list the rules under the field. Each PasswordRequirement takes whether it is met; the list doesn’t read the password, so the rules stay yours.

Sizes

Disabled

Best practices

Do
  • Set autoComplete to current-password for sign-in and new-password for sign-up, so password managers do the right thing.
  • Show the rules with PasswordRequirements while people type a new password, ticking each as it’s met.
  • Keep the show toggle, so people can check what they typed on a phone.
Don’t
  • Block pasting. It stops password managers and helps nobody.
  • Show the rules only as an error after submitting.

API reference

PasswordInput

Holds the value and whether it shows, and draws the box. Renders a <div>.

PropTypeDefault
size
Control height; matches Input and Button.
'sm' | 'md' | 'lg''md'
autoComplete
What password managers fill in.
'current-password' | 'new-password' | 'off'—
defaultValue / value
The password, uncontrolled or controlled.
string—
onValueChange
Called as the password changes.
(value, details) => void—
defaultVisible / visible
Whether the password shows, uncontrolled or controlled.
boolean—
onVisibleChange
Called when it is shown or hidden, including on submit.
(visible, details) => void—
name / required / disabled / readOnly
Form options, as on a native input.
string | boolean—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

PasswordInputControl

The native input. Renders an <input>.

PropTypeDefault
placeholder
Shown while empty.
string—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

PasswordInputToggle

Shows and hides the password. Renders a <button> with aria-pressed.

PropTypeDefault
aria-label
Stays the same in both states; aria-pressed says which one.
string'Show password'
children
Replaces the eye glyph.
ReactNode | (state) => ReactNode—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

PasswordInputCapsLock

An arrow shown while Caps Lock is on and the field has focus. Renders a <span role=status>.

PropTypeDefault
label
Announced, and shown as a tooltip.
string'Caps Lock is on'
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

PasswordRequirements

A checklist of rules for a new password. Renders a <ul>.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

PasswordRequirement

One rule: a dot while unmet, a green check once met. Renders an <li>.

PropTypeDefault
met
Whether the password meets this rule.
booleanfalse
sx
StyleX styles merged after the built-in ones.
StyleXStyles—