Password Input
A password field with a button that shows or hides the password.
Usage
import { PasswordInput, PasswordStrengthMeter } from '@leverui/components';
<PasswordInput />
<PasswordStrengthMeter />
Examples
Sizes
Use the size prop to change the size of the password input.
The password input sizes are mapped to the
Inputcomponent sizes.
Controlled
Use the value and onInput props to control the current value.
Hook Form
Here's an example of how to use the PasswordInput component in a Solid form with native submission.
Controlled Visibility
Use the visible and onVisibleChange props to control the visibility of the password input.
Password is hidden
Strength Indicator
Render the PasswordStrengthMeter component to show the strength of the password. Compute the value prop based on the password input value.
Props
Root
| Prop | Default | Type | Description |
|---|---|---|---|
defaultVisible | false | boolean | Show the password on first render. |
visible | — | boolean | Show the password, when you control it. |
onVisibleChange | — | (visible: boolean) => void | Called when the password is shown or hidden. |
visibilityIcon | — | { on: JSX.Element; off: JSX.Element } | Your own icons for the visibility button. |
rootProps | — | InputGroupProps | Props for the input group around the input. |
ref | — | (element: HTMLInputElement) => void | Receives the native <input> element. |
The value, HTML attributes, event handlers, and Input sizes pass to the
<input> inside. Control the value with onInput. The visibility button keeps
focus in the input and has tabIndex={-1}, so Tab skips it.
PasswordStrengthMeter shows four segments by default. value is a number
from zero to max, which defaults to four. Labels: Low, Medium, or High.
Selected segments: red, orange, or green. The meter does not read the password.
Score it yourself and pass the result.
Customize with CSS
Import styles.css once, before your own CSS.
PasswordInput: .leverui-password-input on the group,
.leverui-password-input__visibility-trigger on the button, plus the
data-visible and data-disabled attributes. The button is a native
type="button" with the classes of a small ghost Button.
PasswordStrengthMeter: .leverui-password-strength-meter on the root, and
__track, __segment, and __label on the parts. The root has
data-strength-level="low" | "medium" | "high". Selected segments have
data-selected.
Variables, for one meter or a whole theme:
--leverui-password-strength-selected-background,
--leverui-password-strength-unselected-background,
--leverui-password-strength-segment-height,
--leverui-password-strength-segment-radius,
--leverui-password-strength-label-font-size,
--leverui-password-strength-label-line-height.
class and style also work.