Replies: 1 comment 6 replies
-
I'm pretty sure this is a bug in MUI's Autocomplete control. I was having the exact same issue - I have a form using react-hook-form with useFieldArray and MUI's Autocomplete - and I kept seeing an annoying flicker. After putting in a lot of debug statements, I discovered that MUI passes a value of "" to the Autocomplete's textfield when the control is initially rendered (even though the Autocomplete has a value). Normally this isn't an issue, but if a component above your autocomplete has a "key" prop, it'll completely re-render and you'll see the flicker when this happens. You can see the issue in-depth in this modified version of your codesandbox: (you'll need to open the developer console) https://codesandbox.io/p/sandbox/objective-cannon-9m3gtz?file=%2Fsrc%2FfieldArray.js I was able to "fix" it by writing a wrapper component around TextField. This wrapper would check and see if TextField had been touched, and if not it would use a default value that I passed in (rather than ""). Once touched it would start using the value from params.inputProps.value. Hopefully you were able to find a workaround, I'm mostly writing this for anyone else who comes across this issue. I may file a bug report with MUI later. |
Beta Was this translation helpful? Give feedback.
-
Hi ,
i have created a Form which uses react-hook-form. The form is dynamic and uses the useFieldArray to add the dropdowns dynamically , the dropdowns are created using the Material UI Autocomplete/TextField combo. There is a button to add the dropdown dynamically on the screen using the append method of useFieldArray. I see that the dropdown flickers as and when i add new dropdowns. This occurs only if i import the FormState.Errors or FormState.isValid in the screen. Please note the Autocomplete is a controlled component.
This code sample from codeSandBox demonstrates the issue .
is there a way to avoid this flicker issue? what might be causing it?
Beta Was this translation helpful? Give feedback.
All reactions