When implementing Bootstrap accordions in my projects, I encountered an issue where closing one accordion would cause the others to also close when reopened.
To address this problem, I utilized the collapse and show classes in Bootstrap to enable users to manually toggle each accordion. Initially, all accordions are open, and I envision them being manually turned on and off by the user. If a user manually closes or opens an accordion, I want that specific accordion to be the only one affected, without any interaction with the other accordions. In other words, toggling one accordion should not impact the state of the others.
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@200;300;400;500;600;700;800;900&display=swap');
.new-listing-head h1 {
color: #000;
font-family: Inter;
font-size: 40px;
font-style: normal;
font-weight: 600;
line-height: normal;
}
/* Additional CSS styles here */
</style>
<div class="listing-accordion">
<div class="accordion" id="accordionExample">
<div class="accordion-item">
<div class="accordion-header">
<div class="accordion-button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<div style="display: block; margin-left: 16px;" class="listing-accord-head">
<span>General Settings</span>
<span>analysis of order trends in one year</span>
</div>
</div>
</div>
<div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#accordionExample">
<div class="accordion-body">
<!-- Listing Search -->
<div class="listing-search">
<!-- Rest of the HTML content -->
</div>
</div>
</div>
<!-- Images -->
<div class="accordion-item images-analysis">
<div class="accordion-header">
<div class="accordion-button" data-bs-toggle="collapse" data-bs-target="#collapsetwo" aria-expanded="false" aria-controls="collapsetwo">
<div style="display: block; margin-left: 16px;" class="listing-accord-head">
<span>Images</span>
<span>analysis of order trends in one year</span>
</div>
</div>
</div>
<div id="collapsetwo" class="accordion-collapse collapse show" data-bs-parent="#accordionExample">
<div class="accordion-body">
<div class="image-accordion-main">
<!-- Image content goes here -->
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d8bab7b7acabacaab9a898edf6ebf6ea">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>
<script src="//js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>
<script>
// Disable the toggling behavior of Bootstrap accordion
document.querySelectorAll('.accordion-button').forEach(button => {
button.addEventListener('click', function (e) {
e.stopPropagation();
});
});
</script>