-
-
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
[TextField] How to leverage CSS input validation #16903
Conversation
- InputBase now applies valueFilled when uncontrolled and without FormControlContext. - Added/Updated comments for use of valueFilled class.
Details of bundle changes.Comparing: 78db8a0...9db0d30
|
7a9d22b
to
9db0d30
Compare
@jonkelling Hey, thank you for looking into it. I wish we discussed it primarily in an issue. I have explored another solution. I don't see much value in exposing the filled state. I think that you are trying to solve a validation issue. In this case, I would encourage one of these: 1. use the native browser feature or 2. use a react form library like formik. |
This comment has been minimized.
This comment has been minimized.
@oliviertassinari I just took a look at your update. Sorry, it seems I'm doing everything in the wrong order! It appears like that will work, and that I may have jumped the gun. I'll try to go through the right channel next time. |
I literally thought about using :valid and remember saying to myself, "naw.. that won't work, clearly I need to do it this way..." and was all proud of myself. Thanks again for the help!! 👍 |
@oliviertassinari It appears that |
@jonkelling Following the new customization demo, I have assumed that the problem you were trying to solve was related to the validation of the field. Could you expand on the use case of changing the design for a filled input, that is not related to validation? Do you control the input? If you do, you could do something like this: themes.overrides = {
MuiInputBase: {
root: props => ({
color: props.value ? 'green' : null,
}),
},
}, |
@oliviertassinari I was under the impression that the I originally tried that using It did not work with the method on
I will play with it a bit more, but this certainly is the hook I was looking for in the first place! Since themes can be nested, I would imagine this provides all of the flexibility one would need. In that case it would make my PR totally unnecessary, which would be great. The only difference, I suppose, is that this method generates a lot of extra classes--right?--but I would guess that's not a performance concern at all. I typically look inside implementations instead of relying totally on the docs, but I wonder if an example in docs would have clued me in earlier. I'll get back to you after I play with it a bit more. Thanks again!!! |
@oliviertassinari It seems like styles generated using the Perhaps as a result of some sort of optimization, like consolidating style tags or something? |
@jonkelling I have tried to without any luck. I was hoping that we could do: const theme = createMuiTheme({
overrides: {
MuiOutlinedInput: {
root: {
"& fieldset": props => ({
borderLeftWidth: props.value ? 4 : 1
})
}
}
}
}); But it doesn't work. https://codesandbox.io/s/material-demo-74qkt. This will most likely be solved in #6115. I would encourage you to create your own wrapping component. As for the validation change, I think that we can accept them. |
I have not looked into Anyway, I understand if not and will go forward with wrapping the components otherwise. |
@jonkelling Here is the concern: I doubt that many people would leverage this new class name. This is particularly useful for SASS users. I would hope that for edge cases, the component wrapping approach is OK. And in the future, the feature should be built-in. |
@oliviertassinari True true. I didn't mean to push, but I thought I'd give it a last shot. Overall, I've been impressed with the progress of this library since it was in beta. Thanks for all your work! |
@jonkelling Thank you! |
This update applies the CSS class
Mui-valueFilled
toInputBase
andInputLabel
based on whether theinput
has an empty value. This allows for styling filled fields without the need for external logic.An example is provided in
/src/pages/components/text-fields/CustomizedInputs.js
.I did not find an open issue related to this. I will happily add one if it's useful.
Other notes:
There are some discrepancies in the use of
filled
in some of the existing components. For example,FormLabel
has afilled
class that reflects the value, butfilled
is used for the filled variant in other components. That's unrelated to this PR--just an observation.Thanks!