Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions packages/mui-material/src/styles/responsiveFontSizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,28 @@ export default function responsiveFontSizes(themeInput, options = {}) {
});
}

const responsive = responsiveProperty({
cssProperty: 'fontSize',
min: minFontSize,
max: maxFontSize,
unit: 'rem',
breakpoints: breakpointValues,
transform,
});

// https://github.com/mui/material-ui/issues/40255
// Preserve the original font size at the largest breakpoint.
// Grid alignment can snap the max value away from the original designed size.
if (breakpointValues.length > 0) {
const lastBreakpoint = breakpointValues[breakpointValues.length - 1];
responsive[`@media (min-width:${lastBreakpoint}px)`] = {
fontSize: `${Math.round(maxFontSize * 10000) / 10000}rem`,
};
}

typography[variant] = {
...style,
...responsiveProperty({
cssProperty: 'fontSize',
min: minFontSize,
max: maxFontSize,
unit: 'rem',
breakpoints: breakpointValues,
transform,
}),
...responsive,
};
});

Expand Down
27 changes: 27 additions & 0 deletions packages/mui-material/src/styles/responsiveFontSizes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,33 @@ describe('responsiveFontSizes', () => {
});
});

it('should preserve the original font size at the largest breakpoint', () => {
// Regression test for https://github.com/mui/material-ui/issues/40255
// h4 (34px = 2.125rem, lineHeight 1.235) has a font size that falls between
// grid alignment points, causing alignProperty to snap it ~1.6px away.
// Uses px input to also verify that the largest-breakpoint value is
// normalized to rem (consistent with the other breakpoints).
const defaultVariant = {
fontFamily: '"Roboto", "Helvetica", "Arial", sans-serif',
fontSize: '34px',
fontWeight: 400,
letterSpacing: '0.00735em',
lineHeight: 1.235,
};

const theme = createTheme({
typography: {
h4: defaultVariant,
},
});
const { typography } = responsiveFontSizes(theme);
expect(
typography.h4[`@media (min-width:${defaultTheme.breakpoints.values.lg}px)`],
).to.deep.equal({
fontSize: '2.125rem',
});
});

it('should handle variants that have been reset to undefined', () => {
const theme = createTheme({
typography: {
Expand Down
Loading