I created a toggle functionality that allows me to show or hide a div with information.
I am looking for a way to have only one toggle active, meaning that only one div should be visible at any given time.
By clicking on the arrow, I can activate the toggle and display the div. If I click on a different line, the previously displayed div will be hidden and only the current one will be shown.
.html
<div *ngFor="let item of Items">
<div class="d-flex flex-row divCamposEtxra">
<div (click)="toggle(item)">
<img *ngIf="item.shown" src="https://img.icons8.com/flat_round/64/000000/collapse-arrow--v1.png" style=" height: 30px;margin-right: 8px;"/>
<img *ngIf="!item.shown" src="https://img.icons8.com/flat_round/64/000000/expand-arrow--v1.png" style=" height: 30px;margin-right: 8px;"/>
</div>
<div>
{{item.name}}
</div>
<div style="margin-left:auto;margin-right: 12px;">
{{item.id}}
</div>
</div>
<div class="d-flex flex-column" *ngIf="item.shown">
<span>INFO</span>
</div>
</div>
.ts
toggle(item) {
item.shown = !item.shown;
}
Issue
https://i.sstatic.net/S9b2H.png
I want to ensure that only one div is open at a time, so when I click on a different one, the previous div should automatically close/hide.