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

[Badge][base] Drop component prop #37028

Merged
merged 4 commits into from
Apr 28, 2023
Merged

Conversation

hbjORbj
Copy link
Member

@hbjORbj hbjORbj commented Apr 26, 2023

BREAKING CHANGE

It will be covered by codemod, see #36831

For Base UI components, the component prop value should be moved to slots.root:

 <Badge
-  component="span"
+  slots={{ root: "span" }}
 />

If using TypeScript, you should add the custom component type as a generic on the Badge component.

-<Badge
+<Badge<typeof CustomComponent>
   slots={{ root: CustomComponent }}
   customProp="foo"
 />

@hbjORbj hbjORbj self-assigned this Apr 26, 2023
@hbjORbj hbjORbj added component: badge This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base breaking change labels Apr 26, 2023
@mui-bot
Copy link

mui-bot commented Apr 26, 2023

Netlify deploy preview

Bundle size report

Details of bundle changes

Generated by 🚫 dangerJS against 3bf3cc2

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 26, 2023
@hbjORbj hbjORbj added this to the MUI Base stable release milestone Apr 26, 2023
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 26, 2023
@@ -89,6 +85,20 @@ The following code snippet applies a CSS class called `my-badge` to the badge sl
<Badge slotProps={{ badge: { className: 'my-badge' } }} />
```

#### Usage with TypeScript

In TypeScript, you can specify the custom component type used in the `slots.root` as a generic to the unstyled component. This way, you can safely provide the custom compoenent's props directly on the compnent:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In TypeScript, you can specify the custom component type used in the `slots.root` as a generic to the unstyled component. This way, you can safely provide the custom compoenent's props directly on the compnent:
In TypeScript, you can specify the custom component type used in the `slots.root` as a generic parameter of the unstyled component. This way, you can safely provide the custom root's props directly on the component:

Copy link
Member Author

Choose a reason for hiding this comment

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

will do the same for other components' markdown too

/>

{/* @ts-expect-error onClick must be specified in the custom root component */}
<Badge<typeof CustomRoot> slots={{ root: CustomRoot }} onClick={() => {}} />
Copy link
Member

Choose a reason for hiding this comment

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

IMO this test was pretty specific to a button. I don't think we need to have it in all components

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed

@@ -77,7 +76,7 @@ const Badge = React.forwardRef(function Badge<RootComponentType extends React.El
className: classes.root,
});

const BadgeComponent = slots.badge || 'span';
const BadgeComponent = slots.badge ?? 'span';
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
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

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

One more minor remark. The rest looks good!

:::

Use the `component` prop to override the root slot with a custom element:
Use the `slots.root` prop to override the root slot with a custom element:
Copy link
Member

Choose a reason for hiding this comment

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

I'd remove this paragraph and change the next one to: "Use the slots prop to override the root or any other interior slot."

@michaldudak
Copy link
Member

The changes look OK. Please make sure the build check pass and it should be good to go.

@hbjORbj hbjORbj merged commit 590c1b3 into mui:master Apr 28, 2023
binh1298 pushed a commit to binh1298/material-ui that referenced this pull request May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: badge This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants