[Typography] Apply fontFamily to custom typography variants#48501
Open
starboyvarun wants to merge 1 commit into
Open
[Typography] Apply fontFamily to custom typography variants#48501starboyvarun wants to merge 1 commit into
starboyvarun wants to merge 1 commit into
Conversation
Custom variants added via `createTheme({ typography: { myVariant: { ... } } })`
were placed in the `other` object and deep-merged as-is, without the
`fontFamily` (or `allVariants`) injection that `buildVariant` applies to
the 13 built-in variants. This caused custom variants to always render
with the browser default font regardless of the theme fontFamily.
Iterate over `other` and inject `fontFamily` and `allVariants` into each
value that is an object, matching the behavior of `buildVariant`. Explicit
per-variant `fontFamily` overrides in `other` are preserved because the
spread is `{ fontFamily, ...allVariants, ...value }`.
Deploy previewhttps://deploy-preview-48501--material-ui.netlify.app/ Bundle size
Check out the code infra dashboard for more information about this PR. |
mj12albert
requested changes
May 8, 2026
| }, | ||
| }; | ||
|
|
||
| // Inject fontFamily and allVariants into any custom typography variant objects in `other` |
Member
There was a problem hiding this comment.
This change would incorrectly treat "inherit" as a custom variant
createTheme({
typography: {
fontFamily: 'Inter',
inherit: { fontSize: 'inherit' },
},
})
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.
Summary
Fixes #35939.
Custom typography variants added via
createTheme({ typography: { myVariant: { color: 'red' } } })did not inherit the themefontFamily(orallVariantsCSS). They ended up with the browser's default font because they were placed inotherand deep-merged as-is, bypassing thebuildVariantcall that injectsfontFamilyfor the 13 built-in variants (h1–overline, etc.).Fix: In
createTypography, iterate overotherand for each object-valued key injectfontFamilyandallVariantsbefore the merge, matchingbuildVariantbehavior. Explicit per-variantfontFamilyinsideotheris still respected because the user's value wins:{ fontFamily, ...allVariants, ...value }.Test plan