Skip to content
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

Closed
wants to merge 11 commits into from

Conversation

sai6855
Copy link
Contributor

@sai6855 sai6855 commented May 7, 2024

part of #41281

What does this PR do

  1. Introduce slots and slotProps
  2. Deprecate IconComponent

Note: There are no slots related tests in skipped array in TableSortLabel.test.js, so i didn't touched that file

@sai6855 sai6855 marked this pull request as draft May 7, 2024 13:06
@sai6855 sai6855 added component: table This is the name of the generic UI component, not the React module! deprecation New deprecation message package: material-ui Specific to @mui/material package: codemod Specific to @mui/codemod labels May 7, 2024
@mui-bot
Copy link

mui-bot commented May 7, 2024

Netlify deploy preview

TableSortLabel: parsed: +2.56% , gzip: +2.23%

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against d9dfdfd

@sai6855 sai6855 marked this pull request as ready for review May 7, 2024 15:14
@sai6855 sai6855 requested a review from DiegoAndai May 7, 2024 15:34
@sai6855 sai6855 force-pushed the add-slots-tablesortlabel branch from 615da9d to e256e02 Compare May 7, 2024 16:26
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label May 8, 2024
Copy link
Member

@DiegoAndai DiegoAndai left a 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' });
Copy link
Member

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} />
Copy link
Member

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} />

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@sai6855 sai6855 May 9, 2024

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)

Copy link
Member

@DiegoAndai DiegoAndai May 9, 2024

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?

Copy link
Member

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:

Copy link
Member

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

Copy link
Member

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 through as, 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 be slotProps.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.

Copy link
Member

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:

  1. We could say the replacement is slots.icon but it's not the same (replaces entire slot)
  2. We could implement the icon prop which behaves as IconComponent does right now. I think it's a common-enough case to change the icon to justify a dedicated prop.

@siriwatknp

Copy link
Contributor Author

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 ?

Copy link
Member

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.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label May 9, 2024
@sai6855
Copy link
Contributor Author

sai6855 commented May 10, 2024

@DiegoAndai
I believe any solution we decide on should also be applied here, is that correct? https://github.com/mui/material-ui/pull/42167/files#diff-17e191be5b15145ab92ea1328de101d094c242aca08febe51dedbd2a87aa7d39R106

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label May 20, 2024
@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged and removed PR: out-of-date The pull request has merge conflicts and can't be merged labels May 23, 2024
@DiegoAndai
Copy link
Member

Hey @sai6855! thanks for working on this. Please see #41281 (comment).

@sai6855 sai6855 closed this Aug 3, 2024
@siriwatknp
Copy link
Member

siriwatknp commented Dec 6, 2024

@sai6855 Can you reopen this and continue working on it? We have finalized to finish #41281 in v6.

@sai6855
Copy link
Contributor Author

sai6855 commented Dec 6, 2024

@sai6855 Can you reopen this and continue working on it? We have finalized to finish #41281 in v6.

Yup sure, I'll open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: table This is the name of the generic UI component, not the React module! deprecation New deprecation message package: codemod Specific to @mui/codemod package: material-ui Specific to @mui/material PR: out-of-date The pull request has merge conflicts and can't be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants