-
Notifications
You must be signed in to change notification settings - Fork 8
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
Allow uncontrolled usage of form input components #172
Comments
I haven't really bothered to try it, but I think we could remove the The |
I haven't really looked into it very closely yet either, but we both know the code-base quite well, so should be able to make a pretty educated guess.... I agree that for some of the atoms, all that is required is to remove
So, if we are to work on this, the |
Yeah, the @ismay what do you think about the select components? Fairly simple and straight forward? |
That one seems pretty easy to fix. It currently does this: componentDidUpdate() {
if (this.shouldDoAutoGrow()) {
this.setHeight()
}
} So the auto-grow logic is executed in the So if we want to support an uncontrolled version, we need to also have this logic in the |
Well we'd have to introduce state somewhere. It's a bit hard to predict completely, but I guess we could introduce state in the SingleSelect and MultiSelect components, and if there's no value passed it would default to changing local state. It might actually be a breaking change, as currently we default to a We could use the following api: SingleSelect:
MultiSelect:
|
To support both controlled and uncontrolled workflows we would need to separate how to set values, examples given:
As for the FileInput component, React docs says it's always uncontrolled: https://reactjs.org/docs/uncontrolled-components.html#the-file-input-tag Maybe we should only have one component where it always manages its own state? Not sure about this one. |
I do wonder if this point from @HendrikThePendric's top comment isn't applicable here:
I remember that material-ui allowed both controlled and uncontrolled components, but would throw an error if you switched from one to the other for an already mounted component. I'm not sure if that would be possible for our eventual implementation as well, but it does seem like we could be introducing more complexity for ourselves and the user in implementing this. Maybe, if we still really want this, we could look at implementing this in an entirely separate repo/package. That should be very doable, and it would force a clean separation between what we have in ui-core, and the convenience wrappers for users who want them. Plus it'd be a subtle hint that the recommended usage is actually a controlled component. |
I was also considering perhaps introducing a HOC that would have internal state and renders the controlled input. That way we would:
I haven't thought about the technical implementation much, so could be that it's not possible to build this in a generic way.... But in any case, I would really like a solution that avoids us from making our current inputs more complex. |
Adding this to the |
As discussed in this public Slack thread, we should add support for uncontrolled usage to all of our form input components.
If any of the conditions below are problematic, we should discuss before proceeding:
The text was updated successfully, but these errors were encountered: