mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 01:29:11 +08:00
6ee61f6f0b
* feat: support controllable visible of password * test: add some unit test for Password * refactor: visibilityToggle API * test: update snapshots * Update components/input/Password.tsx Co-authored-by: afc163 <afc163@gmail.com>
46 lines
1.0 KiB
Markdown
46 lines
1.0 KiB
Markdown
---
|
|
order: 10
|
|
title:
|
|
zh-CN: 密码框
|
|
en-US: Password box
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
密码框。
|
|
|
|
## en-US
|
|
|
|
Input type of password.
|
|
|
|
```tsx
|
|
import { EyeInvisibleOutlined, EyeTwoTone } from '@ant-design/icons';
|
|
import { Button, Input, Space } from 'antd';
|
|
import React from 'react';
|
|
|
|
const App: React.FC = () => {
|
|
const [passwordVisible, setPasswordVisible] = React.useState(false);
|
|
|
|
return (
|
|
<Space direction="vertical">
|
|
<Input.Password placeholder="input password" />
|
|
<Input.Password
|
|
placeholder="input password"
|
|
iconRender={visible => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
|
|
/>
|
|
<Space direction="horizontal">
|
|
<Input.Password
|
|
placeholder="input password"
|
|
visibilityToggle={{ visible: passwordVisible, onVisibleChange: setPasswordVisible }}
|
|
/>
|
|
<Button style={{ width: 80 }} onClick={() => setPasswordVisible(prevState => !prevState)}>
|
|
{passwordVisible ? 'Hide' : 'Show'}
|
|
</Button>
|
|
</Space>
|
|
</Space>
|
|
);
|
|
};
|
|
|
|
export default App;
|
|
```
|