Repository navigation
[material-ui] Add own variant overrides to Card, Accordion, AppBar, SnackbarContent, Stepper and TablePagination - #49980
Open
siriwatknp wants to merge 13 commits into
Open
siriwatknp wants to merge 13 commits into
siriwatknp wants to merge 13 commits into
Conversation
Deploy previewBundle size
PerformanceNo 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
commented
Dec 5, 2026
Member
Author
There was a problem hiding this comment.
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.
Stepper API page now lists'elevation' | 'outlined', but they do nothing on its<ol>root
Stepper'svariantdescription now says the built-in values have no effect and the prop is for theme variants (84371ea).nit: fixture checks theme typing only for Card, and has no check across sibling components
Fixture now has a themevariantsentry for all six components plus<Card variant="accordionOnly" />(c826ec1).
Member
Author
1 task done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #27267
Summary
Card, Accordion, AppBar, SnackbarContent and Stepper take their
varianttype from Paper, and TablePagination takes it from TableCell. To add a custom variant to one of them, you had to augmentPaperPropsVariantOverridesorTableCellPropsVariantOverrides. That made the value valid on every component built on the same parent, even where it does nothing. For example, addingindicatorEndfor 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,StepperPropsVariantOverridesandTablePaginationPropsVariantOverrides. The new interfaces follow the same approach as Tabs in #47590.For Card, Accordion, AppBar, SnackbarContent and TablePagination, this is not a breaking change:
varianttype. Values that you already added throughPaperPropsVariantOverridesorTableCellPropsVariantOverrideskeep working on these components.varianttype 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 toPaperPropsVariantOverrides) never had an effect on it. Stepper'svariantnow has no built-in values and accepts only what you add toStepperPropsVariantOverrides. 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
variantand declares its own. If the inheritedvariantstays, TypeScript reports that Card extends Paper incorrectly. For Accordion and AppBar,ExtendPaperTypeMapintersects both types and still rejects the custom value.NonNullablebecauseOverridableStringUniononly accepts string types.TablePaginationBasePropsis unchanged. OnlyTablePaginationOwnPropsleaves out and redeclaresvariant.varianton each component makes the proptypes script generate avariantpropType. Each one uses theoneOfType([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 listvarianttoo.varianttype isOverridableStringUnion<never, StepperPropsVariantOverrides>, which is empty until you augment the interface. The value only reachesownerState, for themevariantsmatching. Before this PR, Stepper also passedvariantto its<ol>root as an HTML attribute. Stepper now keeps it out of the DOM. Its propType is a plainPropTypes.string.StepperPropsVariantOverrides, Stepper'svarianttype resolves toundefined, and the proptypes script crashed with "Nothing to handle node of type UndefinedNode".generatePropTypes.tsnow generates an optionalPropTypes.anyfor such a prop, the same output as forunknown. A newtype-neverfixture covers it.Stepper.spec.tsxdropsvariant="elevation", which no longer type-checks.'outlined'and values added to Paper are rejected.Verification
pnpm typescript:ci,pnpm typescript:module-augmentation,pnpm test:nodeandpnpm test:browserpass locally.variantskeyed on a custom value applies the style on all six components.PropTypes.checkPropTypesaccepts a customvarianton all six components. As a control, Drawer'svariantpropType still warns on an unknown value.