--- title: PasswordInput description: "`PasswordInput` is a component that allows users to input passwords with a visibility toggle." links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/password-input/password-input.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/password-input - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-passwordinput--basic --- ```tsx ``` ## Usage ```tsx import { PasswordInput, StrengthMeter } from "@yamada-ui/react" ``` ```tsx import { PasswordInput, StrengthMeter } from "@/components/ui" ``` ```tsx import { PasswordInput, StrengthMeter } from "@workspaces/ui" ``` ```tsx ``` ### Change Variants ```tsx {(variant) => ( )} ``` ### Change Size ```tsx preview {(size) => ( )} ``` ### Change Color Scheme ```tsx {(colorScheme) => ( )} ``` ### Default Visible To display the value by default, set `defaultVisible` to `true`. ```tsx ``` ### Show Strength Meter To display the strength meter, use `StrengthMeter`. ```tsx const [value, setValue] = useState("Password") const getStrength = (password: string): number => { let strength = 0 if (password.length >= 8) strength++ if (/[A-Z]/.test(password)) strength++ if (/[0-9]/.test(password)) strength++ if (/[^A-Za-z0-9]/.test(password)) strength++ return strength } return ( setValue(e.target.value)} /> ) ``` ### Change Border Color To change the border color, set `focusBorderColor` or `errorBorderColor` to the color. ```tsx ``` ### Change Placeholder Color To change the placeholder color, set `_placeholder` to the color. ```tsx ``` ### Disable To disable, set `disabled` to `true`. ```tsx {(variant) => ( )} ``` ### Read-Only To make read-only, set `readOnly` to `true`. ```tsx {(variant) => ( )} ``` ### Invalid To make invalid, set `invalid` to `true`. ```tsx {(variant) => ( )} ``` ### Customize Icon To customize icons, set `on` and `off` of `visibilityIcon` to `ReactNode`. ```tsx , on: }} /> ``` ### Control ```tsx const [visible, setVisible] = useState(true) return ( Password visibility: {visible ? "show" : "hide"} ) ``` ## Props ### PasswordInput | Prop | Default | Type | Description | | ------------------ | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"md"` | `"2xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | `"outline"` | `"filled" \| "flushed" \| "outline" \| "plain"` | The variant of the component. | | `buttonProps` | - | `PasswordInputButtonProps` | The props for the button element. | | `defaultVisible` | `false` | `boolean` | Determines whether the password input is visible by default. | | `elementProps` | - | `InputGroup.ElementProps` | The props for the end element. | | `errorBorderColor` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The border color when the input is invalid. | | `focusBorderColor` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The border color when the input is focused. | | `htmlSize` | - | `number` | The native HTML `size` attribute to be passed to the `input`. | | `invalid` | `false` | `boolean` | If `true`, the field will be invalid. | | `onVisibleChange` | - | `(visible: boolean) => void` | Callback function that is triggered when the visibility of the password input changes. | | `rootProps` | - | `InputGroup.RootProps` | The props for the root element. | | `visibilityIcon` | - | `{ off: ReactNode; on: ReactNode }` | The icons to be used for the visibility toggle. | | `visible` | `false` | `boolean` | Determines the visibility of the password input. | ### StrengthMeter | Prop | Default | Type | Description | | ------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `value` | - | `number` | The value of the password strength meter. | | `getIndicatorProps` | - | `(percent: number) => IndicatorProps` | The props of the password strength meter indicator. | | `max` | `4` | `number` | The maximum value of the password strength meter. | | `withLabel` | `true` | `boolean` | If `true`, the password strength meter will display the label. | ## Accessibility Currently, this section is being updated due to the migration of v2.