-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[material-ui][TextField] InputProps vs inputProps confusion #11377
Comments
Happy to do a pr for this if you're happy having step added to |
didn't test, but I guess you should use update: sry, just checked your sandbox :D you already came up with that. What#s the problem with the inputProps solution? I guess there are more props we don't pass down automagically: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement so it might be consistent to not do it at all. |
@eyn We try to find a tradeoff between the popular properties applied on the input and the bundle size of the component. |
I have added the |
Agree it's a balance and step probably falls outside that line at the moment. Just wanted at least a discussion. Any thoughts about a helpful message in development mode for properties that are valid on |
@eyn I think that it's a good idea 👍 |
So… Is there actually no way to specify the |
@leMaik You can with the <TextField inputProps={{ step: "0.01" }} type="number" /> |
I think that @eyn's idea is brilliant. We could add warnings about this issue at runtime so people don't have to find this issue on GitHub. |
@oliviertassinari Oh, with a small i. 😓 A warning would have helped me a lot, indeed. I'll look into adding them later. 👍 |
we've been running into this problem over and over again(with min/max/step) :D and eventually ended up writing a custom NumberField which deflattens these props. Would it make sense to expose such a component within material-ui? |
@sakulstra Do you have an example of how it works? It could be interesting. |
Pretty sure it isn't 😅 We're using this within formik so i tried to extract the not super exciting gist of what we do ;)
There's probably a more elegant solution to this, bu we basically whitelisted some props which currently aren't forwarded to inputProps automatically and manually forward them. |
@sakulstra Thanks for sharing the implementation. It's a problem we are exploring in #14580. There is one pragmatic option we have considered: we could deprecate the However, there is one downside to it. It breaks the convention almost all the other components are following. What's the purpose of a convention? Create predictability and intuitive APIs. I'm not sure we actually have an intuitive API here. I see a lot of people struggling with the
cc @eps1lon |
@oliviertassinari thanks for the references, looking trough this, it seems like your approach makes a lot more sense! Looking forward to this change ;) |
As a last resort, if the choice is pragmatic and intuitive, I would choose to break convention I suppose. Form in general have always been a pain point with special complexities so they might unique in a sense. Seems like it solves a whole host of problems that would be nice to eliminate. |
@davext The component/DOM structure of TextField is:
it should clarify it |
This comment has been minimized.
This comment has been minimized.
index c33fab4291..7a582b6b84 100644
--- a/packages/material-ui/src/TextField/TextField.js
+++ b/packages/material-ui/src/TextField/TextField.js
@@ -302,7 +302,7 @@ TextField.propTypes /* remove-proptypes */ = {
*/
inputProps: PropTypes.object,
/**
- * Props applied to the Input element.
+ * Props applied to the Input component.
* It will be a [`FilledInput`](/api/filled-input/),
* [`OutlinedInput`](/api/outlined-input/) or [`Input`](/api/input/)
* component depending on the `variant` prop value. Could this diff help? It would at least add a differentiation between the component vs element. |
@mnajdova I'm not sure what the right terminology is. From my perspective, props are first applied to the element, then made available in the component's render method. At this point, I would either propose:
We can likely do these two changes. |
The current convention triggers the lint rule |
Prevent duplicate properties in JSX (react/jsx-no-duplicate-props)
This problem was signaled here since 2018: ESlint give error duplicate error. Is there a solution to fix this issue ? |
Hey everyone, I'm working on this alongside the #41281 work. My current view on how to solve the confusion relying on the slots pattern is: InputPropsTo be deprecated in favor of inputPropsFor this one, I see two options to deprecate in favor of:
I prefer option 1., but wonder about your opinion or if you see other options. |
I opened my proposal as a PR ☝🏼 |
I like this better, hoisting the API that makes sense on top makes sense, however this will fail if the Input slot is changed and it has a different API for the HTML input. I don't think this is very likely to happen, but at least the second option does not suffer from this issue. |
I think option 2 suffers from this as well. If the custom input does not support |
The TextField (nor Input) does not pass the step property through to the input as a step attribute.
Expected Behavior
<Textfield type="number" step="0.01" />
renders a<input type="number" step="0.01" />
Current Behavior
<Textfield type="number" step="0.01" />
renders a<input type="number" />
Steps to Reproduce (for bugs)
Context
Your Environment
The text was updated successfully, but these errors were encountered: