From 5af16fdd48881f341b0fa42e8d0680022f2a120f Mon Sep 17 00:00:00 2001 From: Brijesh Bittu Date: Mon, 27 May 2024 18:57:39 +0530 Subject: [PATCH] [material-ui][responsiveFontSizes] Handled undefined variants (#42412) --- .../mui-material/src/styles/responsiveFontSizes.js | 5 +++++ .../src/styles/responsiveFontSizes.test.js | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/mui-material/src/styles/responsiveFontSizes.js b/packages/mui-material/src/styles/responsiveFontSizes.js index fe0a5a6eda7d4f..e01b0a3e186c5c 100644 --- a/packages/mui-material/src/styles/responsiveFontSizes.js +++ b/packages/mui-material/src/styles/responsiveFontSizes.js @@ -34,6 +34,11 @@ export default function responsiveFontSizes(themeInput, options = {}) { variants.forEach((variant) => { const style = typography[variant]; + + if (!style) { + return; + } + const remFontSize = parseFloat(convert(style.fontSize, 'rem')); if (remFontSize <= 1) { diff --git a/packages/mui-material/src/styles/responsiveFontSizes.test.js b/packages/mui-material/src/styles/responsiveFontSizes.test.js index 2383c2ecddd6c2..bf7da7e0d2a9ef 100644 --- a/packages/mui-material/src/styles/responsiveFontSizes.test.js +++ b/packages/mui-material/src/styles/responsiveFontSizes.test.js @@ -59,6 +59,19 @@ describe('responsiveFontSizes', () => { }); }); + it('should handle variants that have been reset to undefined', () => { + const theme = createTheme({ + typography: { + h1: undefined, + }, + }); + const { typography } = responsiveFontSizes(theme, { + disableAlign: true, + }); + + expect(typography.h1).to.deep.equal(undefined); + }); + describe('when requesting a responsive typography with non unitless line height and alignment', () => { it('should throw an error, as this is not supported', () => { const theme = createTheme({