-
-
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
[material-ui][TableSortLabel] Introduce slots and slotProps #42157
Conversation
Netlify deploy previewTableSortLabel: parsed: +2.56% , gzip: +2.23% Bundle size reportDetails of bundle changes (Toolpad) |
615da9d
to
e256e02
Compare
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.
Thanks for working on this @sai6855!
const root = j(file.source); | ||
const printOptions = options.printOptions; | ||
|
||
replaceComponentsWithSlots(j, { root, componentName: 'TableSortLabel' }); |
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.
Is this required?
className={clsx(classes.icon)} | ||
ownerState={ownerState} | ||
/> | ||
<TableSortLabelIcon as={IconSlot} className={clsx(classes.icon)} {...iconProps} /> |
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.
Shouldn't this be:
const externalForwardedProps = {
slots: {
icon: IconComponent,
...slots
},
slotProps,
};
const [IconSlot, iconProps] = useSlot('icon', {
elementType: TableSortLabelIcon,
externalForwardedProps,
ownerState,
className: classes.icon
});
// ...
<IconSlot {...iconProps} />
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 just realized we did the same in https://github.com/mui/material-ui/pull/41875/files#diff-d626958b0fab135d0026b2cf86b08f733dae8abb98fc406df247b3846dcf8589R651
We will need to fix that 🤔
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.
are you sure?
By going with above approach TableSortLabelIcon
won't be in consideration by below logic and it's styles won't be applied
const elementType = slots[name] || initialElementType; |
slots[name] (here: IconComponent) preceeds over initialElementType ( here: TableSortLabelIcon)
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, I see what's happening. There are some *Component
props that are used as
<DefaultComponent
as={ComponentProp}
/>
But others are used as
const { ComponentProp: DefaultComponent } = props
// ...
<ComponentProp />
Which is different.
If I'm not mistaken, the convention for the slot pattern is to work as the latter: When you provide a slot, it replaces the default completely. Is this correct @siriwatknp?
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.
Other components with the as
behavior:
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 assume codemod should also do same?
Yes, but let's wait for confirmation
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.
Let's wait for @siriwatknp's response, but my proposal would be:
- Deprecate
IconComponent
and keep providing it throughas
, so we keep the same functionality.- Implement
slots.icon
so that it replaces the slot completely, following the pattern- In the deprecation message, the correct replacement for
IconComponent
would beslotProps.icon.as
Agree with the first two. I don't think the last is needed. Currently, we don't document as
prop for Material UI, only component
prop.
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 don't think the last is needed. Currently, we don't document as prop for Material UI, only component prop.
But what should we say the replacement for IconComponent
is? Options:
- We could say the replacement is
slots.icon
but it's not the same (replaces entire slot) - We could implement the
icon
prop which behaves asIconComponent
does right now. I think it's a common-enough case to change the icon to justify a dedicated prop.
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.
Hey @DiegoAndai @siriwatknp any discussion happened on this PR front ?
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.
Sorry for the delay @sai6855. I think this is a special case (the same for other IconComponent
props in the codebase). Let's not deprecate.
@DiegoAndai |
Hey @sai6855! thanks for working on this. Please see #41281 (comment). |
part of #41281
What does this PR do
slots
andslotProps
IconComponent
Note: There are no
slots
related tests inskipped
array inTableSortLabel.test.js
, so i didn't touched that file