Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/data/material/migration/upgrade-to-v9/upgrade-to-v9.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,27 @@ The following deprecated `Backdrop` props have been removed:
- TransitionComponent={CustomTransition}
+ slots={{ root: CustomRoot, transition: CustomTransition }}
+ slotProps={{ root: { className: 'my-class' } }}
```

#### Badge deprecated props removed

Use the [badge-props codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#badge-props) below to migrate the code as described in the following section:

```bash
npx @mui/codemod@latest deprecations/badge-props <path>
```

The following deprecated props have been removed from the `Badge` component:

- `components` → use `slots`
- `componentsProps` → use `slotProps`

```diff
<Badge
- components={{ Root: CustomRoot, Badge: CustomBadge }}
- componentsProps={{ root: { className: 'my-root' }, badge: { className: 'my-badge' } }}
+ slots={{ root: CustomRoot, badge: CustomBadge }}
+ slotProps={{ root: { className: 'my-root' }, badge: { className: 'my-badge' } }}
/>
```

Expand Down
15 changes: 0 additions & 15 deletions docs/pages/material-ui/api/badge.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@
"default": "'default'"
},
"component": { "type": { "name": "elementType" } },
"components": {
"type": { "name": "shape", "description": "{ Badge?: elementType, Root?: elementType }" },
"default": "{}",
"deprecated": true,
"deprecationInfo": "use the <code>slots</code> prop instead. This prop will be removed in a future major release. See <a href=\"https://mui.com/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"componentsProps": {
"type": {
"name": "shape",
"description": "{ badge?: func<br>&#124;&nbsp;object, root?: func<br>&#124;&nbsp;object }"
},
"default": "{}",
"deprecated": true,
"deprecationInfo": "use the <code>slotProps</code> prop instead. This prop will be removed in a future major release. See <a href=\"https://mui.com/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"invisible": { "type": { "name": "bool" }, "default": "false" },
"max": { "type": { "name": "number" }, "default": "99" },
"overlap": {
Expand Down
4 changes: 0 additions & 4 deletions docs/translations/api-docs/badge/badge.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
"component": {
"description": "The component used for the root node. Either a string to use a HTML element or a component."
},
"components": { "description": "The components used for each slot inside." },
"componentsProps": {
"description": "The extra props for the slot components. You can override the existing props or add new ones."
},
"invisible": { "description": "If <code>true</code>, the badge is invisible." },
"max": { "description": "Max count to show." },
"overlap": { "description": "Wrapped shape the badge should overlap." },
Expand Down
22 changes: 0 additions & 22 deletions packages/mui-material/src/Badge/Badge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,6 @@ export interface BadgeOwnProps extends BadgeSlotsAndSlotProps {
BadgePropsColorOverrides
>
| undefined;
/**
* The extra props for the slot components.
* You can override the existing props or add new ones.
*
* @deprecated use the `slotProps` prop instead. This prop will be removed in a future major release. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
*
* @default {}
*/
componentsProps?: BadgeOwnProps['slotProps'] | undefined;
/**
* The components used for each slot inside.
*
* @deprecated use the `slots` prop instead. This prop will be removed in a future major release. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
*
* @default {}
*/
components?:
| {
Root?: React.ElementType | undefined;
Badge?: React.ElementType | undefined;
}
| undefined;
/**
* If `true`, the badge is invisible.
* @default false
Expand Down
36 changes: 2 additions & 34 deletions packages/mui-material/src/Badge/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ const Badge = React.forwardRef(function Badge(inProps, ref) {
className,
classes: classesProp,
component,
components = {},
componentsProps = {},
children,
overlap: overlapProp = 'rectangular',
color: colorProp = 'default',
Expand Down Expand Up @@ -216,16 +214,9 @@ const Badge = React.forwardRef(function Badge(inProps, ref) {

const classes = useUtilityClasses(ownerState);

// support both `slots` and `components` for backward compatibility
const externalForwardedProps = {
slots: {
root: slots?.root ?? components.Root,
badge: slots?.badge ?? components.Badge,
},
slotProps: {
root: slotProps?.root ?? componentsProps.root,
badge: slotProps?.badge ?? componentsProps.badge,
},
slots,
slotProps,
};

const [RootSlot, rootProps] = useSlot('root', {
Expand Down Expand Up @@ -304,29 +295,6 @@ Badge.propTypes /* remove-proptypes */ = {
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The components used for each slot inside.
*
* @deprecated use the `slots` prop instead. This prop will be removed in a future major release. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
*
* @default {}
*/
components: PropTypes.shape({
Badge: PropTypes.elementType,
Root: PropTypes.elementType,
}),
/**
* The extra props for the slot components.
* You can override the existing props or add new ones.
*
* @deprecated use the `slotProps` prop instead. This prop will be removed in a future major release. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
*
* @default {}
*/
componentsProps: PropTypes.shape({
badge: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
}),
/**
* If `true`, the badge is invisible.
* @default false
Expand Down
44 changes: 3 additions & 41 deletions packages/mui-material/src/Badge/Badge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('<Badge />', () => {
expectedClassName: classes.badge,
},
},
skip: ['componentsProp'],
}),
);

Expand Down Expand Up @@ -303,30 +304,7 @@ describe('<Badge />', () => {
});
});

describe('prop: components / slots', () => {
it('allows overriding the slots using the components prop', () => {
const CustomRoot = React.forwardRef((props, ref) => {
const { ownerState, ...other } = props;
return <span {...other} ref={ref} data-testid="custom-root" />;
});

const CustomBadge = React.forwardRef((props, ref) => {
const { ownerState, ...other } = props;
return <span {...other} ref={ref} data-testid="custom-badge" />;
});

render(
<Badge
{...defaultProps}
badgeContent={1}
components={{ Root: CustomRoot, Badge: CustomBadge }}
/>,
);

screen.getByTestId('custom-root');
screen.getByTestId('custom-badge');
});
Comment thread
silviuaavram marked this conversation as resolved.

describe('prop: slots', () => {
it('allows overriding the slots using the slots prop', () => {
const CustomRoot = React.forwardRef((props, ref) => {
const { ownerState, ...other } = props;
Expand All @@ -351,23 +329,7 @@ describe('<Badge />', () => {
});
});

describe('prop: componentsProps / slotProps', () => {
it('allows modifying slots props using the componentsProps prop', () => {
render(
<Badge
{...defaultProps}
badgeContent={1}
componentsProps={{
root: { 'data-testid': 'custom-root' },
badge: { 'data-testid': 'custom-badge' },
}}
/>,
);

screen.getByTestId('custom-root');
screen.getByTestId('custom-badge');
});

describe('prop: slotProps', () => {
it('allows modifying slots props using the slotProps prop', () => {
render(
<Badge
Expand Down
Loading