According to the Angular Material Expansion Panel guide, we have the ability to personalize the appearance of the mat-extension-panel-header
, which in turn allows us to customize the icons.
To begin with, you can hide the default icon by setting the attribute hideToggle
to true. Moreover, we assign the event bindings (opened)
and (closed)
to the panelOpenState
property. Explore more properties of mat-expansion-panel
here.
<mat-expansion-panel (opened)="panelOpenState = true" (closed)="panelOpenState = false" hideToggle="true">
Next, within your mat-panel-description
, include the required custom icons. The displayed icons will change based on the panel's state. In this demonstration, we are using icons from Material Icons.
<mat-panel-description>
<mat-icon *ngIf="!panelOpenState">add</mat-icon>
<mat-icon *ngIf="panelOpenState">remove</mat-icon>
</mat-panel-description>
I have modified the original code provided by Angular documentation to showcase the usage of custom +
and minus
icons to represent the expanded/collapsed state of the mat-extension-panel
. You can view the demo here.