Skip to Content
文档

密码输入

用于收集密码。

设置

¥Setup

如果你还没有该代码片段,请运行以下命令添加 password-input 代码片段。

¥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-input

该代码片段包含 PasswordInput 组件的封闭组件组合。

¥The snippet includes a closed component composition for the PasswordInput component.

用法

¥Usage

import {
  PasswordInput,
  PasswordStrengthMeter,
} from "@/components/ui/password-input"
<PasswordInput />
<PasswordStrengthMeter />

示例

¥Examples

尺寸

¥Sizes

使用 size 属性更改密码输入框的大小。

¥Use the size prop to change the size of the password input.

info

密码输入框大小映射到 Input 组件大小。

¥The password input sizes are mapped to the Input component sizes.

受控

¥Controlled

使用 valueonChange 属性控制当前页面。

¥Use the value and onChange props to control the current page.

钩子表单

¥Hook Form

以下是如何将 PasswordInput 组件与 react-hook-form 结合使用的示例。

¥Here's an example of how to use the PasswordInput component with react-hook-form.

受控可见性

¥Controlled Visibility

使用 visibleonVisibleChange 属性控制密码输入框的可见性。

¥Use the visible and onVisibleChange props to control the visibility of the password input.

Password is hidden

强度指示器

¥Strength Indicator

渲染 PasswordStrengthMeter 组件,显示密码强度。根据密码输入 value 计算 value 属性。

¥Render the PasswordStrengthMeter component to show the strength of the password. Compute the value prop based on the password input value.

Medium

属性

¥Props

根元素

¥Root

PropDefaultType
defaultVisible false
boolean

The default visibility state of the password input.

visible
boolean

The controlled visibility state of the password input.

onVisibleChange
(visible: boolean) => void

Callback invoked when the visibility state changes.

visibilityIcon
{ on: React.ReactNode; off: React.ReactNode }

Custom icons for the visibility toggle button.

Previous

数字输入

Next

PIN 码输入