[material-ui][Typography] Enforce type checking for responsive typography shorthand in the sx prop by Fenomen-Alex · Pull Request #49055 · mui/material-ui · GitHub
Skip to content

[material-ui][Typography] Enforce type checking for responsive typography shorthand in the sx prop - #49055

Open
Fenomen-Alex wants to merge 8 commits into
mui:masterfrom
Fenomen-Alex:fix/issue-42918-responsive-typography-sx
Open

[material-ui][Typography] Enforce type checking for responsive typography shorthand in the sx prop#49055
Fenomen-Alex wants to merge 8 commits into
mui:masterfrom
Fenomen-Alex:fix/issue-42918-responsive-typography-sx

Conversation

@Fenomen-Alex

Copy link
Copy Markdown

Closes #42918.

Summary

The typography shorthand in the sx prop is typed as string, which leaves responsive usage ({ xs: ..., sm: ... }) unchecked against the theme typography variants. This tightens the type for the Typography component so invalid responsive variants are caught at compile time.

Changes

  • packages/mui-material/src/Typography/Typography.d.ts
    • Added exported TypographySxProps type:
      ```ts
      export type TypographySxProps = SxProps & {
      typography?: string | Partial<Record<Breakpoint, TypographyProps[variant]>> | undefined;
      };
      ```
    • TypographyOwnProps.sx now uses TypographySxProps. Custom variants remain supported via the string fallback.
  • AlertTitle, DialogContentText, DialogTitle, Link — updated the sx prop type from SxProps<Theme> to TypographySxProps since they extend Typography and their previous declaration was incompatible with the narrowed type.
  • packages/mui-material/src/Typography/typography.spec.tsx — added type tests for valid scalar/responsive/array/function usage plus an @ts-expect-error for an invalid variant key.

Verification

  • `pnpm typescript` passes across all monorepo projects (incl. docs).
  • `pnpm prettier` and `pnpm eslint` are clean.
  • `pnpm test:unit Typography` passes (96 tests).
  • No runtime or `propTypes` changes, so no API docs regeneration was required.

Note

As discussed in #42918, the type is applied to the Typography component first as a starting point; extending it to other components could be a follow-up.

@Fenomen-Alex

Copy link
Copy Markdown
Author

@code-infra-dashboard

code-infra-dashboard Bot commented Aug 29, 2026

Copy link
Copy Markdown

Deploy preview

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

Bundle size

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) 0B(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


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

@Fenomen-Alex

Copy link
Copy Markdown
Author

Hi! The test-label-applied CI check is failing because this PR has no labels. Could a maintainer add the appropriate labels (e.g. component: typography, typescript), matching the ones on #42918? Thanks!

@zannager zannager added the scope: typography Changes related to typography. label Aug 31, 2026
@zannager
zannager requested a review from siriwatknp August 31, 2026 14:06
@Fenomen-Alex

Fenomen-Alex commented Aug 31, 2026

Copy link
Copy Markdown
Author

Failed test is not related to this PR (only Typography .d.ts changes). This is a known flaky WebKit timing test from #48328 — the nested 200+200ms select timer chain races the test's 450ms sleep on loaded CircleCI runners (see upstream #49024).

@Fenomen-Alex

Copy link
Copy Markdown
Author

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

Labels

scope: typography Changes related to typography.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[material-ui][Typography] Enforce responsive typography type checking in sx prop

2 participants