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

1.0 KiB

order title
10
zh-CN en-US
密码框 Password box

zh-CN

密码框。

en-US

Input type of password.

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;