-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Theme] Merge components and slots props #35477
Conversation
@material-ui/core: parsed: +0.06% , gzip: +0.07% |
it('merge components and componentsProps props', () => { | ||
expect( | ||
resolveProps( | ||
{ components: { Input: 'Input' }, componentsProps: { input: 'input' } }, |
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.
{ components: { Input: 'Input' }, componentsProps: { input: 'input' } }, | |
{ components: { Input: 'Input' }, componentsProps: { input: { prop: 'input' } } }, |
This is a more valid use-case, same for the slotProps
.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
Ah, I think I got your point.
const output = { ...props }; | ||
|
||
Object.keys(defaultProps).forEach((propName: keyof T) => { | ||
if (output[propName] === undefined) { | ||
if (propName.toString().match(/^(components|componentsProps|slots|slotProps)$/)) { | ||
output[propName] = { |
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.
For the slotProps
& componentsProps
, should we merge the second level too?
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.
Yeah, that's better.
const defaultSlotProps = (defaultProps[propName] || {}) as T[keyof T]; | ||
const slotProps = props[propName] as {} as T[keyof T]; | ||
output[propName] = {} as T[keyof T]; |
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.
TypeScript is hard to get right for logic like this 🥲
@mnajdova Ready for another round of review. |
...(defaultProps[propName] as any), | ||
...(output[propName] as any), | ||
}; | ||
} else if (propName.toString().match(/^(componentsProps|slotProps)$/)) { |
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.
Should we also merge props like TransitionProps
(just by one depth lile slots
and components
?
To solve #34978
Or should it be a distinct PR ?
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 think it should be a separate PR. I propose to keep it small to fix the main issue first.
@mnajdova @flaviendelangle Should we consider this as a new feature (minor release) or a patch? |
No strong opinion, I'll let @mnajdova answer 👍 |
This is how it should have worked anyways, so I would consider it a bug fix, so a patch should be fine. |
close #34214