question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug(Theming Angular Material): Custom typography not applied to standard typography levels in mat.core-theme() or all-component-themes()

See original GitHub issue

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Tried to change the font-family so that e.g. body-1 everywhere has font family Arial. But it only changed the font-family in mat components, not outside in normal divs.

$my-typography: mat.define-typography-config(
  $font-family: 'Arial',
);
$my-theme: mat.define-light-theme((
  typography: $my-typography,
  color: (
    primary: $dicey-primary,
    accent: $dicey-accent,
    warn: $dicey-warn,
  ))
);
@include mat.all-component-themes($my-theme);

Similar problem was reported here, but not solved: https://github.com/angular/components/issues/23683#issue-1015421891


It works when I do it with all-component-typographies:

$my-typography: mat.define-typography-config(
  $font-family: 'Arial',
);
@include mat.all-component-typographies($my-typography);

Reproduction

Steps to reproduce:

  1. Add custom theme with typography
  2. See if body tag font-family changes

Expected Behavior

Bodys font family changes to custom font family

Actual Behavior

The body font family is standard Roboto

Environment

  • Angular: 13.1.2
  • CDK/Material: 13.1.1
  • Browser(s): Firefox
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 11

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
umutesencommented, Nov 21, 2022

So I think the problem is that you need to pass in your custom typography to the mat.core mixin. Here’s a config that worked for me both for the headline and the “Some text” under it.

$candy-app-primary: mat.define-palette(mat.$indigo-palette);
$candy-app-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
$candy-app-theme: mat.define-light-theme((
  color: (
    primary: $candy-app-primary,
    accent: $candy-app-accent
  ),
  typography: mat.define-typography-config(
    $font-family: 'Arial',
  ),
));

@include mat.core($candy-app-theme);
@include mat.all-component-themes($candy-app-theme);

Alternatively you can include the all-component-typographies like you mentioned above since that’s what mat.core does internally anyway.

mat-core does not appear to allow any parameters on v15:

Module build failed (from ./node_modules/sass-loader/dist/cjs.js): SassError: Only 0 arguments allowed, but 1 was passed. ┌──> src/styles.scss 33│ @include mat.core($my-theme);

1reaction
steffenheescommented, Feb 11, 2022

Yes, that are all nice workarounds. I already mentioned that it works with all-component-typographies. But the bug is, that it is not working with all-component-themes. And this has to be fixed. Please.

I just tried out the kids-theme example on the website , and this is not working either.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular material - custom typography does not apply
I call the default class that comes with this component and invoking the mat.typography-level mixin I try to configure it. .mat-toolbar{ @ ...
Read more >
Customizing Typography - Angular Material
Typography is a way of arranging type to make text legible, readable, and appealing when displayed. Angular Material's theming system supports customizing the ......
Read more >
Custom Theme for Angular Material Components Series: Part 2
First, we created an Angular Project with a custom theme, a dark theme, custom typography for headings and couple of helper modules (...
Read more >
@angular/material | Yarn - Package Manager
The Angular team builds and maintains both common UI components and tools to help you build your own custom components. The team maintains...
Read more >
Customizing the Typography Theme for a Packaged Angular ...
In Creating a Packaged and Themeable Angular Material Component we created a self contained installable Angular component that was also themeable.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found