-
-
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
Changes from 1 commit
d06afb4
29bed4a
98c8ef5
9fa55bc
467a916
55a3c0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,14 +68,30 @@ async function generateProptypes(program: ttp.ts.Program, sourceFile: string) { | |
if (['children', 'state'].includes(prop.name) && component.name.startsWith('DataGrid')) { | ||
return false; | ||
} | ||
let shouldDocument = true; | ||
let shouldExclude = false; | ||
prop.filenames.forEach((filename) => { | ||
// Don't include props from external dependencies | ||
if (/node_modules/.test(filename)) { | ||
shouldDocument = false; | ||
Comment on lines
-73
to
-75
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. That is a good point I did not think about. 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more.
It seems that this problem exists in MUI Core as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The suffix 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. |
||
const definedInNodeModule = /node_modules/.test(filename); | ||
|
||
if (definedInNodeModule) { | ||
// TODO: xGrid team should consider removing this to generate more correct proptypes as well | ||
if (component.name.includes('Grid')) { | ||
shouldExclude = true; | ||
} else { | ||
const definedInInternalModule = /node_modules\/@mui/.test(filename); | ||
// we want to include props if they are from our internal components | ||
// avoid including inherited `children` and `classes` as they (might) need custom implementation to work | ||
if ( | ||
!definedInInternalModule || | ||
(definedInInternalModule && ['children', 'classes'].includes(prop.name)) | ||
) { | ||
shouldExclude = true; | ||
} | ||
} | ||
} | ||
}); | ||
return shouldDocument; | ||
|
||
// filtering out `prop.filenames.size > 0` removes props from unknown origin | ||
return prop.filenames.size > 0 && !shouldExclude; | ||
}, | ||
}); | ||
|
||
|
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.