[card] Remove deprecated CardHeader props#47995
Conversation
Netlify deploy previewBundle size report
|
There was a problem hiding this comment.
Pull request overview
Removes the deprecated CardHeader props (titleTypographyProps / subheaderTypographyProps) and updates the implementation, TypeScript types, type tests, and documentation to rely on slotProps instead (including adding an upgrade-to-v9 migration note).
Changes:
- Removed deprecated props from
CardHeaderruntime implementation and PropTypes. - Removed deprecated props (and related generics) from
CardHeaderTypeScript definitions. - Updated type tests and API docs JSON, and added a v9 migration snippet/codemod pointer.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/mui-material/src/CardHeader/CardHeader.spec.tsx | Replaces deprecated prop type tests with slotProps-based tests (currently has several missing @ts-expect-error annotations). |
| packages/mui-material/src/CardHeader/CardHeader.js | Removes deprecated prop handling and PropTypes entries (note: removed prop names may now leak via ...other). |
| packages/mui-material/src/CardHeader/CardHeader.d.ts | Removes deprecated props and related generics from public TS types. |
| docs/translations/api-docs/card-header/card-header.json | Removes deprecated prop entries from translated API docs. |
| docs/pages/material-ui/api/card-header.json | Removes deprecated prop entries from the generated API docs page JSON. |
| docs/data/material/migration/upgrade-to-v9/upgrade-to-v9.md | Adds migration guidance and codemod command for the removed CardHeader props. |
Comments suppressed due to low confidence (1)
packages/mui-material/src/CardHeader/CardHeader.js:88
- After removing
titleTypographyProps/subheaderTypographyPropsfrom the destructuring, those props will now remain in...otherand end up being forwarded to the root slot (as unknown DOM attributes) if consumers still pass them. Consider explicitly destructuring and discarding these removed props (without supporting them) to avoid leaking them to the DOM and triggering React unknown-prop warnings.
const {
action,
avatar,
component = 'div',
disableTypography = false,
subheader: subheaderProp,
title: titleProp,
slots = {},
slotProps = {},
...other
} = props;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
36354a8 to
1398df1
Compare
| export type CardHeaderProps< | ||
| RootComponent extends React.ElementType = CardHeaderTypeMap['defaultComponent'], | ||
| AdditionalProps = {}, | ||
| TitleTypographyComponent extends React.ElementType = 'span', | ||
| SubheaderTypographyComponent extends React.ElementType = 'span', | ||
| > = OverrideProps< | ||
| CardHeaderTypeMap< | ||
| AdditionalProps, | ||
| RootComponent, | ||
| TitleTypographyComponent, | ||
| SubheaderTypographyComponent | ||
| >, | ||
| RootComponent | ||
| >; |
There was a problem hiding this comment.
We should add this also in the migration guide that CardHeaderProps does not support these two generic parameters now (Use slotProps). Because CardHeaderProps is a public TS type.
| // @ts-expect-error | ||
| titleTypographyProps: true, | ||
| slotProps: { | ||
| title: true, | ||
| }, |
There was a problem hiding this comment.
How come title slot props support boolean?
There was a problem hiding this comment.
From Claude Code:
Slot prop types resolve through
SlotComponentPropstoPartial<ComponentPropsWithRef<T>> & TOverrides. WhenTOverridesis an empty override interface likeCardHeaderTitleSlotPropsOverrides(designed for module augmentation), the intersection simplifies toPartial<ComponentPropsWithRef<T>>— a type where every property is optional. In TS, primitives liketrueare assignable to any type where all properties are optional, because there are no required properties to violate.
The suggested fix is to add & object to
so it becomes (Partial<React.ComponentPropsWithRef<TSlotComponent>> & TOverrides & object)
Unlike
& anywhich destroys all type info,& objectpreserves autocomplete and property checking — it only adds "must be non-primitive." This is exactly what theobjecttype was designed for. The fix is a 2-line change inSlotComponentPropsandSlotComponentPropsWithSlotStateinmui-utils.
There was a problem hiding this comment.
Fix suggested can be considered.
There was a problem hiding this comment.
Is this related to the migration PR? Or something extra we need to do? I'm OK adding it here but just wanted to make sure we're not extending scope that much.
There was a problem hiding this comment.
Makes sense to do this change separately so it's easier to isolate if something backfires ~
There was a problem hiding this comment.
This test should be removed? titleTypographyProps is not valid anymore.
| }, | ||
| }} | ||
| />; | ||
| // @ts-expect-error |
| // @ts-expect-error | ||
| titleTypographyProps: true, | ||
| slotProps: { | ||
| title: true, | ||
| }, |
There was a problem hiding this comment.
This test should be removed? titleTypographyProps is not valid anymore.
1398df1 to
b18d040
Compare
Try it here: https://stackblitz.com/edit/crdjeux1?file=src%2FDemo.tsx