Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change default expansion panel arrow colour for angular material

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 {}

enter image description here

like image 679
CloudSeph Avatar asked Oct 03 '17 08:10

CloudSeph


5 Answers

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:

  1. 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.

  2. 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.

like image 162
GreenTeaCake Avatar answered Nov 15 '22 02:11

GreenTeaCake


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;}
like image 5
frfernandezdev Avatar answered Nov 15 '22 02:11

frfernandezdev


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

like image 4
braunpa Avatar answered Nov 15 '22 01:11

braunpa


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;
}
like image 2
Jendrik Avatar answered Nov 15 '22 01:11

Jendrik


for "@angular/material": "^10.2.7"

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

like image 2
Mansour Alnasser Avatar answered Nov 15 '22 00:11

Mansour Alnasser