-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Description
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
Angular Material 17 (Material 2)
Description
I'm encountering an issue where only the primary color is applied when using custom themes in Angular Material 18.
However, this issue does not occur when using pre-built themes from @angular/material/prebuilt-themes
(e.g., magenta-violet.css
). The pre-built theme's accent and warn colors are applied correctly in those cases.
Reproduction
StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-g9u5la
Steps to reproduce:
-
Create a new Angular project or use an existing one:
- If creating a new project, run:
ng new color-theme-issue
- Navigate to the project directory:
cd color-theme-issue
- If creating a new project, run:
-
Install Angular Material 18:
- Run:
ng add @angular/material
- Choose custom theme
- Run:
-
Define custom themes in a Sass file (e.g., styles.scss):
@use "@angular/material" as mat; @include mat.core(); $theme: mat.define-theme( ( color: ( theme-type: dark, primary: mat.$violet-palette, ), . .. ) ) :root { @include mat.all-component-themes($theme); }
-
Use Angular Material components in your template:
<button mat-flat-button>This should use the primary color</button> <button mat-flat-button class="mat-button-accent">This should use the accent color (not visible)</button> <button mat-flat-button class="mat-button-warn">This should use the warn color (not visible)</button>
Expected Behavior
All colors defined in a custom theme should be applied correctly to the Angular Material components, just like when using the pre-built themes from @angular/material/prebuilt-themes.
Actual Behavior
Only the primary color is reflected. The accent and warn colors are not visible in the components.
Environment
Angular CLI: 18.0.2
Node: 20.11.1
Package Manager: npm 10.2.4
OS: linux x64
Angular: 18.0.1
... animations, cdk, common, compiler, compiler-cli, core, forms
... material, platform-browser, platform-browser-dynamic, router
Package Version
@angular-devkit/architect 0.1800.2
@angular-devkit/build-angular 18.0.2
@angular-devkit/core 18.0.2
@angular-devkit/schematics 18.0.2
@angular/cli 18.0.2
@schematics/angular 18.0.2
rxjs 7.8.1
typescript 5.4.5
zone.js 0.14.6