While utilizing Angular Materials, I encountered a challenge with the mat-expansion component. Every time I click on the buttons within the expansion panel, it closes due to the default behavior of mat-panel.
Requirement - The panel should remain expanded when clicking on buttons.
Use Case - In my scenario, I have multiple stacked mat-expansions and I want to use icon buttons to rearrange their positions in the stack. Although I have already implemented the logic for moving them up and down, the issue arises when the panel collapses or expands along with the button clicks.
<mat-expansion-pannel>
<mat-expansion-panel-header>
<mat-panel-title class="title-align">
Image
</mat-panel-title>
<mat-panel-description>
<button mat-icon-button (click) ="moveUp(i)"><i class="material-icons md-18">arrow_upward</i></button>
<button mat-icon-button (click) ="moveDown(i)"><i class="material-icons md-18">arrow_downward</i></button>
<button mat-icon-button color="warn" (click) ="removeWidget(i)">
<i class="material-icons md-18">clear</i>
</button>
</mat-panel-description>
</mat-expansion-panel-header>
</mat-expansion-pannel>
As shown in the code snippet, the goal is for the panel to move up and down without collapsing unexpectedly. One approach could be to disable button clicks on the panel altogether, but since we require button functionality, the objective is for the buttons to function independently without affecting the expansion state.