Skip to content

Commit 25d12df

Browse files
committed
fix(material/schematics): set generated font family on body (#31618)
The custom theme that we generate during `ng add` adds changes the `font` on the `html` element which is problematic, because it affects all the components where we use `rem` units. These changes move the styles to the `body` to resolve the issue. I've also changed the selector for the variables from `html` to `:root`. In practice they're the same, but `:root` seems to be the standard target for global variables. Fixes #31611. (cherry picked from commit 8576ccf)
1 parent 3de927f commit 25d12df

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/material/schematics/ng-add/theming/create-custom-theme.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
/** Create custom theme for the given application configuration. */
10-
export function createCustomTheme(userPaletteChoice: string) {
10+
export function createCustomTheme(userPaletteChoice: string): string {
1111
const colorPalettes = new Map<string, {primary: string; tertiary: string}>([
1212
['azure-blue', {primary: 'azure', tertiary: 'blue'}],
1313
['rose-red', {primary: 'rose', tertiary: 'red'}],
@@ -31,7 +31,9 @@ html {
3131
typography: Roboto,
3232
density: 0,
3333
));
34+
}
3435
36+
body {
3537
// Default the application to a light color theme. This can be changed to
3638
// \`dark\` to enable the dark color theme, or to \`light dark\` to defer to the
3739
// user's system settings.
@@ -43,5 +45,9 @@ html {
4345
background-color: var(--mat-sys-surface);
4446
color: var(--mat-sys-on-surface);
4547
font: var(--mat-sys-body-medium);
46-
}`;
48+
49+
// Reset the user agent margin.
50+
margin: 0;
51+
}
52+
`;
4753
}

0 commit comments

Comments
 (0)