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
- Set
autoCompletetocurrent-passwordfor sign-in andnew-passwordfor sign-up, so password managers do the right thing. - Show the rules with
PasswordRequirementswhile 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.
- 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>.
| Prop | Type | Default |
|---|---|---|
sizeControl height; matches Input and Button. | 'sm' | 'md' | 'lg' | 'md' |
autoCompleteWhat password managers fill in. | 'current-password' | 'new-password' | 'off' | — |
defaultValue / valueThe password, uncontrolled or controlled. | string | — |
onValueChangeCalled as the password changes. | (value, details) => void | — |
defaultVisible / visibleWhether the password shows, uncontrolled or controlled. | boolean | — |
onVisibleChangeCalled when it is shown or hidden, including on submit. | (visible, details) => void | — |
name / required / disabled / readOnlyForm options, as on a native input. | string | boolean | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
PasswordInputControl
The native input. Renders an <input>.
| Prop | Type | Default |
|---|---|---|
placeholderShown while empty. | string | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
PasswordInputToggle
Shows and hides the password. Renders a <button> with aria-pressed.
| Prop | Type | Default |
|---|---|---|
aria-labelStays the same in both states; aria-pressed says which one. | string | 'Show password' |
childrenReplaces the eye glyph. | ReactNode | (state) => ReactNode | — |
sxStyleX 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>.
| Prop | Type | Default |
|---|---|---|
labelAnnounced, and shown as a tooltip. | string | 'Caps Lock is on' |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
PasswordRequirements
A checklist of rules for a new password. Renders a <ul>.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
PasswordRequirement
One rule: a dot while unmet, a green check once met. Renders an <li>.
| Prop | Type | Default |
|---|---|---|
metWhether the password meets this rule. | boolean | false |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |