Setup
If you don't already have the snippet, run the following command to add the
password-input snippet
npx @chakra-ui/cli snippet add password-inputThe snippet includes a closed component composition for the PasswordInput
component.
Usage
import {
PasswordInput,
PasswordStrengthMeter,
} from "@/components/ui/password-input"<PasswordInput />
<PasswordStrengthMeter />Examples
Sizes
Use the size prop to change the size of the password input.
Input component sizes.Controlled
Use the value and onChange props to control the current page.
Hook Form
Here's an example of how to use the PasswordInput component with
react-hook-form.
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 |
|---|---|---|
defaultVisible | false | booleanThe default visibility state of the password input. |
visible | booleanThe controlled visibility state of the password input. | |
onVisibleChange | (visible: boolean) => voidCallback invoked when the visibility state changes. | |
visibilityIcon | { on: React.ReactNode; off: React.ReactNode }Custom icons for the visibility toggle button. |