ant-design/components/input/demo/password-input.md
He Linming 6ee61f6f0b
feat(Input.Password): password visibility controllable (#38216)
* 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>
2022-10-31 21:15:59 +08:00

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;
```