PasswordInput
A field for a password or any other secret the person types. The text is hidden, and a button with an eye shows it to check for mistakes.
import { PasswordInput } from '@sypnia/ui/react'
Signing in
Press the eye to see the password and again to hide it.
Code
import { Actions, Button, Field, Input, PasswordInput } from '@sypnia/ui/react';
// Press the eye to check what you typed.
export default function SignIn() {
return (
<form className="sy-stack" onSubmit={(e) => e.preventDefault()}>
<Field label="Email"><Input type="email" autoComplete="username" defaultValue="laura@northwind.io" /></Field>
<Field label="Password"><PasswordInput defaultValue="harbor-linen-42" /></Field>
<Actions><Button variant="primary" type="submit">Sign in</Button></Actions>
</form>
);
} A new password
The hint gives the rule; the error counts what is missing as you type.
Add 7 more characters: a password needs at least 12.
At least 12 characters. A few unrelated words work well.
Code
import { useState } from 'react';
import { Field, FormGrid, PasswordInput } from '@sypnia/ui/react';
export default function NewPassword() {
const [value, setValue] = useState('short');
const error = value.length > 0 && value.length < 12 ? `Add ${12 - value.length} more characters: a password needs at least 12.` : undefined;
return (
<FormGrid>
<Field label="New password" hint="At least 12 characters. A few unrelated words work well." error={error}>
<PasswordInput autoComplete="new-password" value={value} onChange={(e) => setValue(e.target.value)} />
</Field>
</FormGrid>
);
} Other secrets, and disabled
A pasted database password, and a secret the person cannot change.
Of the database you are importing from. It is not stored.
Ask the owner to change it.
Code
import { Field, FormGrid, PasswordInput } from '@sypnia/ui/react';
// Not only passwords: anything typed that should not be read over a shoulder.
export default function OtherSecrets() {
return (
<FormGrid>
<Field label="Database password" hint="Of the database you are importing from. It is not stored.">
<PasswordInput autoComplete="off" machine placeholder="Paste it here" />
</Field>
<Field label="Webhook secret" hint="Ask the owner to change it.">
<PasswordInput autoComplete="off" disabled defaultValue="whsec_3f9a7c21d4e8" />
</Field>
</FormGrid>
);
} When to use it
Use it when
- Signing in, choosing a new password, or typing any secret: a database password, a webhook secret.
- For a new password set
autoComplete="new-password", so password managers offer to create and save one.
Do not use it when
- The secret is shown to the person, not typed by them: that is CopyField with
secret. - It is a one-time code from an email or an app: that is OtpInput.
- You would ask for the password twice. The eye lets people check it; a second field only doubles the typing.
For everyone
- The eye is a toggle button named «Show» or «Hide», and it says whether it is pressed.
- Pasting is always allowed: password managers depend on it.
- Rules for a new password are in the hint from the start, and the error says what is still missing.
Props
| PasswordInput | Type | Default |
|---|---|---|
machineMachine text (ids, keys, code): set in the mono face. | boolean | |
size | "sm" | "md" | "lg" |