I recently customized a Bootstrap 4 list-group to include collapse functionality.
In my customization, I added a CSS caret arrow with the following behavior: 1. Initially pointing down 2. Clicked once, it points up 3. Clicked again, it returns to the initial downward position
The problem I am facing is that upon the first click, the caret does not respond, only on the second click does it point upwards.
I am using CSS transform selectors to rotate the caret up and down.
Why is this behavior not working as expected? Could I be missing something or doing something incorrectly?
.btn {
box-shadow: none !important;
outline: 0;
}
a:link,
a:visited {
color: #222;
}
a:hover,
a:focus {
color: orange;
}
.list-group-item span {
cursor: pointer;
border: solid #222;
border-width: 0 1px 1px 0;
transform: rotate(40deg);
transition: .3s transform ease-in-out;
display: inline;
padding: 3px;
position: absolute;
right: 0;
margin-top: 10px;
}
.list-group-item .collapsed span {
transform: rotate(-140deg);
margin-top: 10px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col">
<div class="my-5">
<ul class="list-group list-group-flush">
<li class="list-group-item px-0">
<a class="btn" data-toggle="collapse" href="#collapseExample1" role="button" aria-expanded="true" aria-controls="collapseExample1">
<span class="mr-3"></span> Link with href
</a>
<div class="collapse" id="collapseExample1">
<div class="card card-body mt-2">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
</div>
</div>
</li>
<li class="list-group-item px-0">
<a class="btn" data-toggle="collapse" href="#collapseExample2" role="button" aria-expanded="true" aria-controls="collapseExample2">
Link with href <span class="mr-3"></span>
</a>
<div class="collapse" id="collapseExample2">
<div class="card card-body mt-2">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
</div>
</div>
</li>
<li class="list-group-item px-0">
<a class="btn" data-toggle="collapse" href="#collapseExample3" role="button" aria-expanded="true" aria-controls="collapseExample3">
Link with href <span class="mr-3"></span>
</a>
<div class="collapse" id="collapseExample3">
<div class="card card-body mt-2">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>