9

I have the following material custom sass file:

@import '../node_modules/@angular/material/theming';
@include mat-core();

$app-primary: mat-palette($mat-red, 700, 800);
$app-accent: mat-palette($mat-red, 700, 800);
$app-warn: mat-palette($mat-red, 700, 800);
$app-theme: mat-light-theme($app-primary, $app-accent, $app-warn);

$app-input-primary: mat-palette($mat-red, 100, 200);
$app-input-accent: mat-palette($mat-red, 100, 200);
$app-input: mat-light-theme($app-input-primary, $app-input-accent);


@include mat-core-theme($app-theme);
@include mat-checkbox-theme($app-theme);
@include mat-radio-theme($app-theme);
@include mat-input-theme($app-theme);

The styles apply correctly to the checkbox and the radiobox, but do not apply in the input fields.

This is how I define the input field:

<md-form-field>
    <input mdInput placeholder="Card holder name">
</md-form-field>

The image below shows that the red style is applied to the radio, but the input loses the styles

If I change the broken-down includes with the one-liner @include angular-material-theme($app-theme); the red style works on the input, but my idea is to have a different palette for the input fields.

4
  • can you add a screenshot of the output ? Commented Sep 25, 2017 at 9:11
  • @Faisal I added an image. Commented Sep 25, 2017 at 9:34
  • Please see if your input styles are not being overridden with some other css Commented Sep 25, 2017 at 9:36
  • @Faisal, no they are not. :/. I dont have any custom styling for the inputs at this point Commented Sep 25, 2017 at 9:40

3 Answers 3

7

Input field is part of the <md-form-field>. Add the following in your custom sass file:

@include mat-form-field-theme($app-theme); // Form-Field theme
@include mat-input-theme($app-theme);      // Input Theme
Sign up to request clarification or add additional context in comments.

Comments

1

Note that if you use the @use and as mat like: @use '~@angular/material' as mat;

Then you need to use

  @include mat.core-theme($default-theme);
  @include mat.button-theme($default-theme);
  @include mat.form-field-theme($default-theme); // Form-Field theme
  @include mat.input-theme($default-theme);      // Input Theme
  @include mat.checkbox-theme($default-theme);   // Checkbox Theme

Comments

0

for Angular 14, we can apply the theme to all components.

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

1 Comment

The documentation recommends this if you are using all the components. Otherwise, you are just adding unused css to the client browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.