I have an angular expansion panel as shown below. How can i change the color of the arrow below to white?
My code (HTML):
<md-expansion-panel>
<md-expansion-panel-header>
<md-panel-title>
Personal data
</md-panel-title>
<md-panel-description>
Type your name and age
</md-panel-description>
</md-expansion-panel-header>
<md-form-field>
<input mdInput placeholder="First name">
</md-form-field>
<md-form-field>
<input mdInput placeholder="Age">
</md-form-field>
</md-expansion-panel>
My code (TS):
import {Component} from '@angular/core';
/**
* @title Basic expansion panel
*/
@Component({
selector: 'expansion-overview-example',
templateUrl: 'expansion-overview-example.html',
})
export class ExpansionOverviewExample {}
Working code is below:
<md-expansion-panel>
<md-expansion-panel-header class="specific-class">
<md-panel-title>
Personal data
</md-panel-title>
<md-panel-description>
Type your name and age
</md-panel-description>
</md-expansion-panel-header>
<md-form-field>
<input mdInput placeholder="First name">
</md-form-field>
<md-form-field>
<input mdInput placeholder="Age">
</md-form-field>
</md-expansion-panel>
import {Component} from '@angular/core';
/**
* @title Basic expansion panel
*/
@Component({
selector: 'expansion-overview-example',
templateUrl: 'expansion-overview-example.html',
styles: [`
::ng-deep .specific-class > .mat-expansion-indicator:after {
color: white;
}
`],
})
export class ExpansionOverviewExample {}
Explanation:
In order to style nested elements dynamically added by Angular Material component you need to use special selector ::ng-deep. That allows to work around view encapsulation.
In order to override built-in component styles applied dynamically you need to increase CSS specificity for your selector. That's the reason for adding additional CSS class specific-class. If you gonna use selector ::ng-deep .mat-expansion-indicator:after expansion component will override it.
its works for me in this way
Html
<mat-accordion>
<mat-expansion-panel class="specific-class">
<mat-expansion-panel-header>
<a mat-button>Lorem ipsum dolor sit amet.</a>
</mat-expansion-panel-header>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nobis, placeat.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nobis, placeat.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nobis, placeat.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nobis, placeat.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nobis, placeat.</li>
</ul>
</mat-expansion-panel>
</mat-accordion>
Css
/deep/ .mat-expansion-indicator::after, .mat-expansion-panel-header-description { color: red;}
You do not have to use ng-deep. Instead you can add this code to your style sheet:
.mat-expansion-panel-header-description,
.mat-expansion-indicator::after {
color: white;
}
See GitHub-Documentation https://github.com/angular/components/tree/master/src/material/expansion
You can simply add it to your global styles.css file. Works for me atleast in version 7.2.
.mat-expansion-indicator::after {
color: green;
}
You add encapsulation: ViewEncapsulation.None
property into your @Component
decorator
@Component({
selector: '...',
templateUrl: '...',
styleUrls: ['...'],
encapsulation: ViewEncapsulation.None // <----
})
then
.mat-expansion-panel-body {
padding: 0 !important;
}
Then this CSS will work fine with !important or without
::ng-deep
and /deep/
will not work on the new version of angular/material
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With