-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
[fields] Fix multi input fields root element props order and types #7225
[fields] Fix multi input fields root element props order and types #7225
Conversation
These are the results for the performance tests:
|
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.
Great job !
I just added a few suggestions of props people can't override
packages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.tsx
Outdated
Show resolved
Hide resolved
/** | ||
* Type of the `input` element. It should be [a valid HTML5 input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types). | ||
*/ | ||
type: PropTypes.oneOf([ |
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.
We can skip this one, we are forcing a value on our side and I don't think people should override it
Or if we want people to override it, we should put it before the spread
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.
I believe that we are changing inputmode
and type
can easily be changed externally. 🤔
But I agree, that for this kind of component we should not allow it to change. 😉 👍
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.
Oh you are right I mixed both of them sorry 😬
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.
Did we consider the option to copy the solution the main repo uses to fix this problem?
type: PropTypes.oneOf([ | |
type: PropTypes /* @typescript-to-proptypes-ignore */.string, |
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.
Nope, we did not look into such solution. But as Flavien mentioned, this change has eventually been reverted in favor of not supporting custom type
value, because it does not make sense for these components.
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.
This new propTypes strategy sounds to be a good compromise 👍
/** | ||
* Type of the `input` element. It should be [a valid HTML5 input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types). | ||
*/ | ||
type: PropTypes.oneOf([ |
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.
Did we consider the option to copy the solution the main repo uses to fix this problem?
type: PropTypes.oneOf([ | |
type: PropTypes /* @typescript-to-proptypes-ignore */.string, |
/** | ||
* This prop helps users to fill forms faster, especially on mobile devices. | ||
* The name can be confusing, as it's more like an autofill. | ||
* You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill). | ||
*/ | ||
autoComplete: PropTypes.string, | ||
/** | ||
* If `true`, the `input` element is focused during the first mount. | ||
* @default false | ||
*/ | ||
autoFocus: PropTypes.bool, | ||
className: PropTypes.string, | ||
/** | ||
* The color of the component. | ||
* It supports both default and custom theme colors, which can be added as shown in the | ||
* [palette customization guide](https://mui.com/material-ui/customization/palette/#adding-new-colors). | ||
* @default 'primary' | ||
*/ | ||
color: PropTypes.oneOf(['error', 'info', 'primary', 'secondary', 'success', 'warning']), |
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.
From the DX perspective, I'm not sure that any of the TextField APIs should be duplicated here. I wonder if we shouldn't lean on this approach instead: https://mui.com/material-ui/api/menu/#inheritance. The advantage is that it makes it clear where the props are coming from, and what's the structure of the component. The downside is that people have to learn the pattern once. If they already learned it from MUI Core, they should be good.
Beyond the docs DX question, it would also solve this problem: #7225 (comment).
/** | |
* This prop helps users to fill forms faster, especially on mobile devices. | |
* The name can be confusing, as it's more like an autofill. | |
* You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill). | |
*/ | |
autoComplete: PropTypes.string, | |
/** | |
* If `true`, the `input` element is focused during the first mount. | |
* @default false | |
*/ | |
autoFocus: PropTypes.bool, | |
className: PropTypes.string, | |
/** | |
* The color of the component. | |
* It supports both default and custom theme colors, which can be added as shown in the | |
* [palette customization guide](https://mui.com/material-ui/customization/palette/#adding-new-colors). | |
* @default 'primary' | |
*/ | |
color: PropTypes.oneOf(['error', 'info', 'primary', 'secondary', 'success', 'warning']), |
I have tried to fix the inheritance automatic docs generation in #7294, I got one step closer, but it wasn't enough to make it work.
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.
From the DX perspective, I'm not sure that any of the TextField APIs should be duplicated here. I wonder if we shouldn't lean on this approach instead: https://mui.com/material-ui/api/menu/#inheritance. The advantage is that it makes it clear where the props are coming from, and what's the structure of the component. The downside is that people have to learn the pattern once. If they already learned it from MUI Core, they should be good.
Really good point. I did not investigate the MUI core solution to this issue deep enough.
In regards to api documentation your point makes total sense and would allow better differentiation between component and inherited props.
But it still leaves some open questions on edge cases:
- what if we inherit only some of the component props? I'd imagine it might cause a bit of confusion as to which props are actually valid
- what about PropTypes then? They may once again be way out of sync, with what props are actually available on a component. Or we don't care that much about their correctness because a possibly small amount of users are not using TS?
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.
what if we inherit only some of the component props?
@LukasTy The pattern I proposed is not an option in this case. It only works when the component forwards all the props.
what about PropTypes then?
I think that the prop-type should stay broad and links the source, like in this example: https://mui.com/material-ui/api/tree-item/#props TransitionProps
.
if (['children', 'state'].includes(prop.name) && component.name.startsWith('DataGrid')) { | ||
return false; |
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.
The changes made me think that we forgot to clean up the list in the main repo: mui/material-ui#35571.
// Don't include props from external dependencies | ||
if (/node_modules/.test(filename)) { | ||
shouldDocument = false; |
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.
Maybe we should differentiate between peer dependencies and dependencies. For example, MUI X has the TextField as a peer dependency, so MUI X doesn't control which props from the API are supported or not. So the generation could be off. It could tell developer a prop value isn't there when using a version of MUI X that was built with mui/material@v5.6.0 while the developer is on mui/material@v5.7.0.
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.
That is a good point I did not think about. 🤔
So, all in all, MUI (core) preference is declare inheritance and don't focus on having correct/full PropTypes?
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.
don't focus on having correct/full PropTypes?
MUI Core avoids duplicating the prop-types. If the prop-type is fully declared, then when the component receives a wrong prop, the component warns twice: once in the parent and once in the actually inherited component. It assumes it's clearer to not duplicate the prop-type, to warn once and in the lower level. It teaches developers the lower-level component structure.
I think that how the docs display the information is a different topic from how the prop-type handles the case. Soon or later, we will need to generate the API docs from the types, not from the prop-types.
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.
MUI Core avoids duplicating the prop-types. If the prop-type is fully declared, then when the component receives a wrong prop, the component warns twice: once in the parent and once in the actually inherited component. It assumes it's clearer to not duplicate the prop-type, to warn once and in the lower level. It teaches developers the lower-level component structure.
It seems that this problem exists in MUI Core as well.
Did a small test with DateField
component in a fresh JS project and my change added one extra warn/error as you mentioned, but there already are 4 others being thrown by the inherited components. 🙈
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.
The suffix 2
is strange on these component names.
Yeah, definitely. From what I recall, we decided to duplicate some of the props because the UX of the inherited prop is not good enough on the API pages. Too many developers where asking the same question: can I use prop xxx? The relevant issue: mui/material-ui#18288 to fix this.
Created from #7135 (comment)
StackProps
{...props}
at the end to allow for our defined prop value overridinggenerateProptypes
to generate more correct finalPropTypes
classes
&children
from inherited types