antd-password-input-strength
antd-password-input-strength copied to clipboard
Always throws an error if the password is pasted into the input box
Describe the bug Throws an error when the password is pasted instead of typed.
To Reproduce
- I used this example from the docs:
- Type a password which is accepted by the component without error. Copy that and paste it back.
- 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 thevalidator
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>
);
}