Is there a simple way to implement an arrow (>) to show the
aria-expanded="true" or aria-expanded="false"
states in the Bootstrap 4 accordion using either Angular2 or plain CSS?
I have gone through several tutorials and attempted numerous methods, but it seems like I am missing something.
I've experimented with just CSS, but the arrow doesn't appear (although this approach might be correct):
.card .card-header:after{
float: right;
border: 2px solid #f07f09;
border-width: 0 3px 3px 0;
padding: 6px;
margin-right: 10px;
}
I also tried using ngClass
, but my problem is that it applies the arrow state to all elements with the code below (is there a way to incorporate the index for this to work?):
<i [ngClass]="{'right':!expanded, 'down':expanded}"></i>
and the function setting the state:
(click)="changeDropdownArrowState()"
Function in my component:
changeDropdownArrowState () {
this.expanded = !this.expanded;
}
My HTML:
<div class="card">
<div class="card-header" id="headingOne">
<h2 class="mb-0">
<button class="btn btn-link btn-block text-left" type="button" data-toggle="collapse"
data-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne" (click)="changeDropdownArrowState()">
<h1>Personal Details
<i [ngClass]="{'right':!expanded, 'down':expanded}"></i>
</h1>
</button>
</h2>
</div>
<div id="collapseOne" class="collapse" aria-labelledby="headingOne" data-parent="#retailCliamAccordian">
<div class="card-body">
some text
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingTwo">
<h2 class="mb-0">
<button class="btn btn-link btn-block text-left collapsed" type="button" data-toggle="collapse"
data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo" (click)="changeDropdownArrowState()">
<h1>Product Details
<i [ngClass]="{'right':!expanded, 'down':expanded}"></i>
</h1>
</button>
</h2>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#retailCliamAccordian">
<div class="card-body">
other text
</div>
</div>
</div>
My CSS:
i {
float: right;
border: 2px solid #f07f09;
border-width: 0 3px 3px 0;
padding: 6px;
margin-right: 10px;
}
.right {
transform: rotate(-45deg);
}
.down {
transform: rotate(45deg);
}
https://i.sstatic.net/CrDF8.png
Another possible solution could involve utilizing the aria-expanded="true/false"
attribute.