antd-password-input-strength icon indicating copy to clipboard operation
antd-password-input-strength copied to clipboard

Always throws an error if the password is pasted into the input box

Open ThePiyushAggarwal opened this issue 2 years ago • 0 comments

Describe the bug Throws an error when the password is pasted instead of typed.

To Reproduce

  1. I used this example from the docs: image
  2. Type a password which is accepted by the component without error. Copy that and paste it back.
  3. You will see an error "Password is too weak"

Expected behavior

  • I think it should work right on paste as well.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser : Chrome

Fix I will be using in my project for now

  • level changes only after the validator function has started
import { useEffect, useState } from "react";
import "./styles.css";
import { Form } from "antd";
import { PasswordInput } from "antd-password-input-strength";

export default function App() {
  const [level, setLevel] = useState(0);
  const [form] = Form.useForm();

  const minLevel = 1;
  const errorMessage = "Password is too weak";

  useEffect(() => {
    form.validateFields();
  }, [level, form]);

  return (
    <Form form={form}>
      <Form.Item
        name="test"
        rules={[
          {
            validator: async () => {
              return level >= minLevel
                ? Promise.resolve()
                : Promise.reject(errorMessage);
            },
            message: errorMessage
          }
        ]}
      >
        <PasswordInput onLevelChange={setLevel} />
      </Form.Item>
    </Form>
  );
}

ThePiyushAggarwal avatar Dec 26 '22 14:12 ThePiyushAggarwal