Search code examples
angulartypescriptangular-materialangular15

custom Typography not working in angular material 15 after update


This code worked great for customizing my typography in my entire application with angular 14

@use '@angular/material' as mat;
@import '@angular/material/theming';

$my-typography: mat-typography-config($font-family: "Lato, sans-serif");

@include mat.core($my-typography);

While updating Angular Material & cdk to 15 this error keeps happening:

Error: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
HookWebpackError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Only 0 arguments allowed, but 1 was passed.
  ┌──> src\app\core\sass\cecom-theme.scss
11│ @include mat.core($my-typography);
  │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invocation
  ╵
  ┌──> node_modules\@angular\material\core\_core.scss
8 │ @mixin core() {
  │        ━━━━━━ declaration
  ╵
  src\app\core\sass\cecom-theme.scss 11:1  core()
  src\app\core\sass\cecom-theme.scss 11:1  root stylesheet

tried ng generate @angular/material:mdc-migration but it does not detect any issues in that file in particular.


Solution

  • I did this:

    @import '@angular/material/theming';
    $custom-typography: mat-typography-config($font-family: '"Inter", "Helvetica Neue", sans-serif;');
    @include mat-typography-hierarchy($custom-typography);
    @include mat-core();
    

    In other words, I moved the typography config argument out of mat-core and into this mat-typography-hierarchy mixin.

    Details of which I found here: https://material.angular.io/guide/typography

    And news that this was something new found here: https://rc.material.angular.io/guide/mdc-migration