-
-
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
slots
overrides do not merge with the theme
#34214
Comments
In general, this makes sense to me. We can do a POC with Joy UI in the next quarter together with the Data Grid integration. |
Would you consider it a breaking change ? Technically it's a behavior change but I don't know who would currently use the theme to define |
I don't think so. If my understanding is correct, the change is basically merging
Yeah, I feel that it will benefit the X components more than in general usage. I agree with the proposal that the |
Yes |
Agree with the proposal. I would generally consider this as a bug fix, not a breaking change. I would assume this is what people would expect, but I also think this is not widely used so far, so it may even go unnoticed. |
components
overrides do not merge with the theme
components
overrides do not merge with the themeslots
overrides do not merge with the theme
A PR was opened for it in #35088 |
Problem
How does the theme default props work
Users can define default props for there components using the theme as follow:
The props passed to the theme, will then be merged with the props passed to the component with a shallow merge.
material-ui/packages/mui-utils/src/resolveProps.ts
Lines 13 to 17 in 50e2b94
What is the problem with the slots ?
The way the merge currently works, makes it very difficult, or even impossible for users to override a slot component (or some slot component props) directly from the theme.
For instance, if a user wants to customize the left and right arrow icons on all the date pickers of its application, he will not be able to use the theme.
Since the merge is a shallow merge, the
props.components
passed toDatePicker
overrides the one stored in the theme default props instead of being merged with it.Example with the props: working
Example with the theme: not working
When is this problem blocking ?
I did not find any actual use case on the core and I don't think users should always override the slots through the theme.
But on bigger components like the one provided by X, the ability of overriding some slot once and for all can make some customization a lot easier.
Here are a few example I have in mind:
DataGrid + Joy
@siriwatknp did a POC during our retreat (https://github.com/mui/mui-x/pull/5360/files).
The behavior could be even better if users could just import a method to populate the theme with joy slots.
This could look something like:
Custom DatePicker with custom input
The current version of the pickers requires a
renderInput
prop.This prop can be defined in the theme to avoid defining it on each picker (with
@ts-ignore
to avoid having TS complain that the prop is required)Working example
In v6, we are discussing replacing this prop with a component slot to be coherent with the other component customization.
But it would prevent users from defining it in the theme, which would be a clean solution I would like to encourage.
Proposal
For the
components
prop, increase the depth of the merge of one.Advantages
Disadvantages
Follow up
I focused this RFC on the
components
prop, but the same can be discussed for thecomponentsProps
prop.The text was updated successfully, but these errors were encountered: