Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

DARK: Single page accordion do not open #211

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions assets/accordion.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
function accordionClickHandler() {
this.classList.toggle("active");
const accordionContent = this.nextElementSibling;

if (accordionContent.style.maxHeight) {
/**
* If the accordion is currently open, then close it
*/
accordionContent.style.maxHeight = null;
} else {
/**
* If the accordion is currently closed, then open it
*/
accordionContent.style.maxHeight = accordionContent.scrollHeight + "px";
}
}

function setupAccordion() {
const accordionHeaders = document.querySelectorAll(".accordion-header");

accordionHeaders.forEach((accordion) => {
accordion.addEventListener("click", function () {
this.classList.toggle("active");

const accordionContent = this.nextElementSibling;

if (accordionContent.style.maxHeight) {
/**
* If the accordion is currently open, then close it
*/
accordionContent.style.maxHeight = null;
} else {
/**
* If the accordion is currently closed, then open it
*/
accordionContent.style.maxHeight = accordionContent.scrollHeight + "px";
}
});
// remove the event listener before adding it to prevent duplicates
accordion.removeEventListener("click", accordionClickHandler);
accordion.addEventListener("click", accordionClickHandler);
});
}

Expand Down