Skip to content

[material-ui] Add own variant overrides to Card, Accordion, AppBar, SnackbarContent, Stepper and TablePagination - #49980

Open
siriwatknp wants to merge 13 commits into
mui:masterfrom
siriwatknp:paper-based-variant-overrides
Open

siriwatknp wants to merge 13 commits into
mui:masterfrom
siriwatknp:paper-based-variant-overrides

Conversation

@siriwatknp

@siriwatknp siriwatknp commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

closes #27267

Summary

Card, Accordion, AppBar, SnackbarContent and Stepper take their variant type from Paper, and TablePagination takes it from TableCell. To add a custom variant to one of them, you had to augment PaperPropsVariantOverrides or TableCellPropsVariantOverrides. That made the value valid on every component built on the same parent, even where it does nothing. For example, adding indicatorEnd for Accordion also made <Card variant="indicatorEnd"> and <AppBar variant="indicatorEnd"> type-check.

Each of these six components now has its own interface: CardPropsVariantOverrides, AccordionPropsVariantOverrides, AppBarPropsVariantOverrides, SnackbarContentPropsVariantOverrides, StepperPropsVariantOverrides and TablePaginationPropsVariantOverrides. The new interfaces follow the same approach as Tabs in #47590.

declare module '@mui/material/Accordion' {
  interface AccordionPropsVariantOverrides {
    indicatorEnd: true;
  }
}

const theme = createTheme({
  components: {
    MuiAccordion: {
      variants: [{ props: { variant: 'indicatorEnd' }, style: { /* ... */ } }],
    },
  },
});

<Accordion variant="indicatorEnd" />; // OK
<Card variant="indicatorEnd" />; // type error

For Card, Accordion, AppBar, SnackbarContent and TablePagination, this is not a breaking change:

  • Each new type builds on the parent's variant type. Values that you already added through PaperPropsVariantOverrides or TableCellPropsVariantOverrides keep working on these components.
  • If you don't augment the new interfaces, the variant type of each component is the same as before.

Stepper is the exception. It stopped rendering a Paper in #22564, so Paper's values ('elevation', 'outlined' and anything added to PaperPropsVariantOverrides) never had an effect on it. Stepper's variant now has no built-in values and accepts only what you add to StepperPropsVariantOverrides. Code such as <Stepper variant="outlined"> now fails to type-check. The value never did anything at runtime, so this PR treats the change as a bug fix.

The other five components are safe to cherry-pick to v9.x. The Stepper change narrows a type, so please confirm that it can go to v9.x too.

For reviewers

  • Each component leaves out the inherited variant and declares its own. If the inherited variant stays, TypeScript reports that Card extends Paper incorrectly. For Accordion and AppBar, ExtendPaperTypeMap intersects both types and still rejects the custom value.
  • The new type wraps the parent type in NonNullable because OverridableStringUnion only accepts string types.
  • The exported TablePaginationBaseProps is unchanged. Only TablePaginationOwnProps leaves out and redeclares variant.
  • Declaring variant on each component makes the proptypes script generate a variant propType. Each one uses the oneOfType([oneOf([...]), string]) pattern that Paper and TableCell already use, so custom values don't log a warning. The API pages of the six components now list variant too.
  • Stepper's variant type is OverridableStringUnion<never, StepperPropsVariantOverrides>, which is empty until you augment the interface. The value only reaches ownerState, for theme variants matching. Before this PR, Stepper also passed variant to its <ol> root as an HTML attribute. Stepper now keeps it out of the DOM. Its propType is a plain PropTypes.string.
  • With nothing added to StepperPropsVariantOverrides, Stepper's variant type resolves to undefined, and the proptypes script crashed with "Nothing to handle node of type UndefinedNode". generatePropTypes.ts now generates an optional PropTypes.any for such a prop, the same output as for unknown. A new type-never fixture covers it.
  • Stepper.spec.tsx drops variant="elevation", which no longer type-checks.
  • The module augmentation test augments each new interface. It checks that the component accepts its own value, that the value does not reach Paper or TableCell, and that a value added to Paper or TableCell still works on the component. For Stepper, it checks the opposite: 'outlined' and values added to Paper are rejected.

Verification

  • The new module augmentation test failed before each change and passes after.
  • pnpm typescript:ci, pnpm typescript:module-augmentation, pnpm test:node and pnpm test:browser pass locally.
  • A server render with theme variants keyed on a custom value applies the style on all six components.
  • PropTypes.checkPropTypes accepts a custom variant on all six components. As a control, Drawer's variant propType still warns on an unknown value.

@siriwatknp siriwatknp added scope: card Changes related to the card. typescript type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. needs cherry-pick The PR should be cherry-picked to master after merge. v9.x labels Dec 5, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-49980--material-ui.netlify.app/
QR code for https://deploy-preview-49980--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+10B(0.00%) ▼-8B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

No regressions in 32 benchmarks · precise to ±7.0% (±11.4% at worst) · ran 2m 27s · details


Check out the code infra dashboard for more information about this PR.

@siriwatknp siriwatknp left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

All addressed in 84371ea and c826ec1. Thanks 🙏

👍 Thanks for this, the per-component interfaces look solid. I checked that each new variant type is identical to the parent type when nothing is augmented, and that a value added to Paper or TableCell still works.

  1. Stepper API page now lists 'elevation' | 'outlined', but they do nothing on its <ol> root
    Stepper's variant description now says the built-in values have no effect and the prop is for theme variants (84371ea).
  2. nit: fixture checks theme typing only for Card, and has no check across sibling components
    Fixture now has a theme variants entry for all six components plus <Card variant="accordionOnly" /> (c826ec1).

@siriwatknp

Copy link
Copy Markdown
Member Author

Review loop done. Both findings are fixed in 84371ea and c826ec1, and the threads are resolved.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs cherry-pick The PR should be cherry-picked to master after merge. scope: card Changes related to the card. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. typescript v9.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow variant overrides in Card

1 participant