-
Notifications
You must be signed in to change notification settings - Fork 933
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
Switching between controlled and uncontrolled input #478
Comments
Hi, could you please reproduce your issue in codesandbox? You can start with this one: http://kcd.im/ds-example It's just really hard to debug your issue with a wall of unformatted code 😅 |
Without spending too much time on it, I think that this should be fixed with: <TextField
InputProps={getInputProps({
placeholder: inputDetails.placeholder,
name: inputDetails.name,
id: inputDetails.id,
value,
})}
label={inputDetails.label}
fullWidth={inputDetails.fullWidth}
/> This way downshift can compose things together properly. |
Sorry about the wall of text it was formatted when i put it in i swear. the problem persists in my code after making your change but when i created the sandbox it did not give the error. Think it might be a version issue (sandbox version is higher than mine)? I don't know ill keep digging. |
Go ahead and keep digging. If you find a bug, feel free to comment here. |
I would think based on your example that you should control the
I'm running into this same issue even though I'm controlling it like that ☝️ but maybe I'm doing it wrong. Its hard to find a full-fledged "controlled" Downshift example anywhere and the docs don't fully explain how to control everything with a concrete example. Once I figure it out I'll try to post it up so others can know how to do it. |
I figured it out. There were states (mostly initially) where I was passing |
I got this error when I had:
but my item didn't have |
I was experiencing this issue as well. Solved it by setting <input
{...getInputProps({
type: "search",
placeholder: "Search",
id: "search",
name: "search",
className: loading ? "loading" : "",
value: props.value,
onChange: e => {
e.persist();
onChange(e, hits, refine);
}
})}
/> |
I have set up an autocomplete with downshift and it works perfectly... except it gives me the following warning whenever i select an option.
Warning: A component is changing a controlled input of type text to be uncontrolled. Input elements should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component
As far as i can tell (by looking at what i set the value to before and after the selection) I am not changing the input to undefined or null (what most commonly causes this issue).
My downshift version is 1.31.16
My node version is 9.2.1
My npm version is 5.10.0
My material ui version is 1.2.3
My code is as follows
Reproducing Bug
To reproduce i type into the autofill field created and select an option from the suggestions that come up.
when a suggestion is selected it creates a warning that I am changing from a controlled to uncontrolled input.
The text was updated successfully, but these errors were encountered: