Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change arrow style for default expansion panel arrow

I have an angular expansion panel as shown below.

enter image description here

But I want to change the the design of the arrow to something like this:

Not expanded:

enter image description here

Expanded:

enter image description here

How? or is it possible for me to do so in angular material? Code below:

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>

TS:

import {Component} from '@angular/core';

/**
 * @title Basic expansion panel
 */
@Component({
  selector: 'expansion-overview-example',
  templateUrl: 'expansion-overview-example.html',
})
export class ExpansionOverviewExample {}
like image 540
CloudSeph Avatar asked Oct 04 '17 02:10

CloudSeph


People also ask

How do you change the mat expansion indicator icon?

panel. expanded">add</mat-icon><mat-icon *ngIf="panel. expanded">remove</mat-icon></mat-panel-description> . By defining panel as a template reference, you can access the expanded state of the mat-expansion-panel directly, removing the need for a variable in the component.

How do you change the mat expansion indicator color?

you can directly go to material. scss in your app if you have installed angular material using npm and change the color of the arrow with class .


1 Answers

Yes it is possible. Give your expansion panel a reference id e.g. example and set the hideToggle property as true.

In the <md-panel-description>, you can place your icons and use the expanded property of the panel to show or hide the relevant icons.

  <md-expansion-panel  class="custom-header" hideToggle="true" #example>
    <md-expansion-panel-header>
      <md-panel-title>
        Personal data
      </md-panel-title>
      <md-panel-description>
        Type your name and age
        <md-icon *ngIf="!example.expanded">play_arrow</md-icon>
        <md-icon *ngIf="example.expanded">arrow_drop_down</md-icon>
      </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>

To provide space between the icon and panel description, add the following classes in your component.css:

.custom-header .mat-expansion-panel-header-title, 
.custom-header .mat-expansion-panel-header-description {
  flex-basis: 0;
}

.custom-header .mat-expansion-panel-header-description {
  justify-content: space-between;
  align-items: center;
}

I have used material icons. You can place your custom icons if you want. Here is a link to stackblitz demo.

like image 71
Faisal Avatar answered Sep 20 '22 07:09

Faisal