As the listed solutions were either not restrictive enough (.mat-mdc-form-field
) or too restrictive for my use case (due to !important
), I came up with two possible alternatives.
- Motivated by this answer, you might use double class names for your selectors to trump single class names, which are used by Material itself:
@mixin typography($theme) {
$custom-typography-config: mat.get-typography-config($theme);
.mat-mdc-form-field.mat-mdc-form-field {
@include mat.typography-level($custom-typography-config, 'input')
}
}
... while this works for some use cases, it is necessary to extend the list of selectors:
@mixin typography($theme) {
$custom-typography-config: mat.get-typography-config($theme);
.mat-mdc-form-field.mat-mdc-form-field,
.mat-mdc-select.mat-mdc-select,
.mat-mdc-menu-item.mat-mdc-menu-item
// further selectors are necessary
{
@include mat.typography-level($custom-typography-config, 'input')
}
}
... which can be problematic when adjustments are made.
- A more generic solution is motivated by this answer and allows to overwrite the typography of the component types itself:
/* Apply custom config */
@include mat.all-component-typographies($my-typography-config);
/* Apply further overwrites */
$form-typography: mat.m2-define-typography-config(
$body-1: mat.m2-define-typography-level(1rem, 1, 400, 'Roboto'),
);
@include mat.checkbox-typography($form-typography);
@include mat.form-field-typography($form-typography);
@include mat.input-typography($form-typography);
@include mat.menu-typography($form-typography);
@include mat.option-typography($form-typography);
@include mat.radio-typography($form-typography);
@include mat.select-typography($form-typography);
You might also exclude several component types or include further ones.