-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[docs] Simplify state management in Text Field demo page #35051
Conversation
managing state of MultilineTextFields component on multiline-flexible. so that every input field has a different state Signed-off-by: PratikDev <87067570+PratikDev@users.noreply.github.com>
managing state of SelectTextFields component. so that every input field has a different state Signed-off-by: PratikDev <87067570+PratikDev@users.noreply.github.com>
managing state of ComposedTextField component. so that every input field has a different state Signed-off-by: PratikDev <87067570+PratikDev@users.noreply.github.com>
Signed-off-by: PratikDev <87067570+PratikDev@users.noreply.github.com>
Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so all fields have synced values. used FormControl here, so that all fields have placeholder's floating animation when one is changed Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so that all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
used the unused state "weightRange" as With Normal TextField's state. Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so that all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so that all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so that all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so that all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so that all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so that all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so that all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so that all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so that all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
added state so that all fields have synced values Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
|
applied eslint and prettier Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
applied eslint and prettier Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
This PR makes all the components controlled. We've discussed making them uncontrolled instead to simplify the code and make the demos more focused on what their primary purpose is. |
oh boyy. i guess i got some misconception. did you mean stateless by "uncontrolled"? |
https://reactjs.org/docs/uncontrolled-components.html Basically, components without the |
understood. as this PR has gone so blurry it could be confusing for anyone. so should I just delete this and create a new one with a more perfect description? or just commit the edits in it? |
hey @michaldudak, haven't received any feedback about this PR for a long time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. With so many PRs and issues, it's hard to prioritize.
I left two comments, but it looks OK in general.
@@ -50,8 +35,7 @@ export default function InputAdornments() { | |||
<FormControl sx={{ m: 1, width: '25ch' }} variant="outlined"> | |||
<OutlinedInput | |||
id="outlined-adornment-weight" | |||
value={values.weight} | |||
onChange={handleChange('weight')} | |||
defaultValue="" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty defaultValue
is not necessary.
@@ -24,8 +18,7 @@ export default function MultilineTextFields() { | |||
label="Multiline" | |||
multiline | |||
maxRows={4} | |||
value={value} | |||
onChange={handleChange} | |||
defaultValue="Controlled" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not controlled anymore. You can remove the defaultValue
at all IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so should remove the defaultValue
from all the input fields?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In cases where it's "Controlled" now, yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we again having some confusion about"controlled" and "uncontrolled" by any chance? because I think I made all of the fields "uncontrolled" as per our discussion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct; all the fields are uncontrolled. That's why having a defaultValue="Controlled" is confusing and I'm asking you to remove the defaultValue
prop where its value is "Controlled" (literally).
Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
sorry for all the confusion we had. but seems we're now on the same page. please check out my recent commit. I've removed all the |
showPassword: !values.showPassword, | ||
}); | ||
}; | ||
const handleClickShowPassword = () => setShowPassword(!showPassword); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing state based on a previous value should use the callback form:
const handleClickShowPassword = () => setShowPassword(!showPassword); | |
const handleClickShowPassword = () => setShowPassword((show) => !show); |
@@ -59,8 +35,7 @@ export default function InputAdornments() { | |||
<FormControl sx={{ m: 1, width: '25ch' }} variant="outlined"> | |||
<OutlinedInput | |||
id="outlined-adornment-weight" | |||
value={values.weight} | |||
onChange={handleChange('weight')} | |||
defaultValue="" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove empty defaultValue
props here as well
@@ -24,8 +18,7 @@ export default function MultilineTextFields() { | |||
label="Multiline" | |||
multiline | |||
maxRows={4} | |||
value={value} | |||
onChange={handleChange} | |||
defaultValue="Controlled" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the defaultValue
props
Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
Signed-off-by: Pratik Dev <87067570+PratikDev@users.noreply.github.com>
Hi, I think I removed all the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now. Thanks for your work!
the PR still shows Open. is there anything more to do from my end? or I'm such a noob in open source who doesn't even know how things work here? |
No, no need to do anything :) It should be included in the next release. We leave PRs open for some time after approval in case other MUI team members would like to comment. |
oh okay. got it. thanks
…On Fri, Dec 9, 2022 at 7:55 PM Michał Dudak ***@***.***> wrote:
No, no need to do anything :) It should be included in the next release.
We leave PRs open for some time after approval in case other MUI team
members would like to comment.
—
Reply to this email directly, view it on GitHub
<#35051 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUYIXMQLMV6E43CT5HTPLGTWMM25RANCNFSM6AAAAAAR2Y3GDE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Fixes #35041
Text Field demo page had several components that weren't managing the state perfectly. some had synced values and some didn't. Since these demos' main purpose isn't to show the usage of controlled vs. uncontrolled modes, I converted all of them to uncontrolled to reduce confusion