-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[RFC] The way to override components and slots #34334
Comments
So, if I understand this correctly, you're proposing that the |
hmm, I forgot that we can use <Select
slotProps={{
listbox: {
component: 'div',
}
}}
/> This sounds better than having another |
Generally, I see two changes are proposed here:
Do I understand the intent correctly? Assuming so, this proposal would only make sense in styled libraries (Material UI and Joy UI). In MUI Base, as explained in #34333 (comment), the |
Just clarifying that I understand the proposal correctly. We would have
Apart from this, in the components inside Material UI and Joy UI, there would be a We don't really need this in Mui Base, as the behavior is the same as Btw, this is how it already works in Material UI, so I don't expect big change anyway, unless I am misunderstanding the proposal. |
Yes, the
I'd say that I expect big change for Material UI because most components are using another pattern. e.g. Accordion has // current
<Accordion TransitionComponent={Slide} TransitionProps={{ delay: 100 }} />
// new
<Accordion slots={{ transition: Slide }} slotsProps={{ transition: { delay: 100 } }} /> |
Marked this as RFC for Material UI and Joy UI only. |
What I meant is that in terms of behavior it will behave the same. For the props surface, we could support both for smoother migration and provide codemods if people want to migrate to the new paradigm sooner. |
Not necessarily. The current pattern in Material UI uses the const AutocompletePaper = styled(Paper, { /* ... */ });
/* ... */
<AutocompletePaper
ownerState={ownerState}
as={PaperComponent}
{...componentsProps.paper}
className={clsx(classes.paper, componentsProps.paper?.className)}
> whereas the |
Yep, agree. We can start introducing |
Yep, component props is "as" and the slot props behave the same as the component props we have on some components, for example |
Update: Joy UI already follows this approach. |
This issue can be closed once all Material UI components support |
Hi there, But I'm not sure its capable of what I'm trying to do.. maybe someone could give some advice? I have a React Component thats based on the MUI Base Now with the Can anyone advise me how I can render a complete different HTML structure / Component and also give it props? The docs I've read are giving me the impression I can only change the HTML Tag (ol to ul, button to a etc.) and css styles. Cheers |
You can pass in props using the |
Okay thats some clarity, but what about the |
What exactly do you have a problem with? This should work: <NumberInput slots={{ input: InputCalculate }} /> |
@michaldudak |
You can use slotProps: <NumberInput slots={{ input: InputCalculate }} slotProps={{ input: { ... } }} /> |
What's the problem? 🤔
Before reading this RFC, please go through #34333 first so that we are on the same page about the meaning of
components
andslots
.From #33416, and #21453 it seems like we are only talking about slot override (replacing the slot). However, for Material UI and Joy UI, we also need a component override (changing the HTML tag of the slot).
What are the requirements? ❓
Proposed solution 🟢
My proposed solution aims for the least breaking changes. All components (MUI Base, Material UI, and Joy UI) should follow this:
Components with a single slot (
root
)component
(existing prop): for changing the root slot's HTML tag. (I think we should not drop this prop because it will be a huge breaking change)For this kind of components, it does not make sense to replace the root slot so having justThis is not true for MUI Base 🤔.component
prop is cleaner.Components with more than one slot
component
(existing prop): for changing the subcomponent of the root slot (could be an HTML tag or React element).slots
andslotsProps
same as [RFC] Rename of thecomponents
prop toslots
#33416slots.{slot}.component
: for changing the subcomponent of the target slot (could be an HTML tag or React element).To replace the HTML of the slot, use
slotsProps={{ listbox: { component: 'div' } }}
.Components that have nested components
See the problem and another example
Flatten the nested component slots with a new name. For example,
TextField
hasInput
as a nested component could look something like this:The text was updated successfully, but these errors were encountered: