Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form Input looses focus upon values validity change #200

Open
ThinhNguyenHoang opened this issue Apr 16, 2022 · 3 comments
Open

Form Input looses focus upon values validity change #200

ThinhNguyenHoang opened this issue Apr 16, 2022 · 3 comments

Comments

@ThinhNguyenHoang
Copy link

ThinhNguyenHoang commented Apr 16, 2022

Hello,
For some reason the form input loses focus when the field validity change (from Invalid to invalid and vice versa) . I don't know if this is the default behavior but it feels annoying as a user (require additional mouse click to re-enter the form) .

Code:
`import { Button, Space } from 'antd';
import React from 'react';
import * as Yup from 'yup'
import { Formik } from 'formik';
import { Form, FormItem, Input} from 'formik-antd';

const validationSchema = Yup.object({
test: Yup.string().required("required")
})
const TestPage = () => (
<>
<Formik onSubmit={(val) => console.log("values", val)} initialValues={{ test: "" }} validationSchema={validationSchema}>
{({ values }) => {
return






}}

</>

);
export default TestPage;`

Expected Result: The user can continue to input even when the field validity change

@elghst
Copy link

elghst commented Apr 26, 2022

Sup! Check your chrome console for a warning that starts like this:
Warning: [antd: Input] When Input is focused, dynamic add or remove prefix / suffix will make it lose focus caused by dom structure change...
If so, the link in the message basically tells you to set default prefix/suffix (the element antd uses to render input validation) to your Input. I just left it blank, the problem is gone :
<Input name="password" placeholder="Password" suffix />

@andrii-muntian-p24
Copy link

andrii-muntian-p24 commented Jun 21, 2022

Hello! Have similar issue here, but do not see any warning message like mentioned above by @elghst.
I think i might find reason for that. It is reproducible on latest for today [email protected] version but not reproduced on 4.1.0 which is set as dependency here in formik-antd codesandbox example.
It seems input is rerendered when validation error is displayed/hided.
Here is issue reproduced example on codesandbox.

How to reproduce:

  • focus to inout
  • click outside of input and see validation error.
  • focus to input again
  • type smth
  • see validation error is gone and input is unfocused

How to fix:

  • still looking for solution

@lscheibel
Copy link

@andrii-muntian-p24 This is an issue with antd but in your case adding hasFeedback={false} to the FormItem or adding showCount to the TextArea should fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants