const { faqsList } = Astro.props;
<div class="faq-accordion max-w-4xl mx-auto">
{ faqsList.map((faq: Faq, index: number) => (
class="py-8 px-5 rounded-md border bg-white focus-within:border-secondary"
class="text-left w-full flex justify-between items-start focus:outline-none"
aria-controls="{`faq-${index}`}"
id="{`faq-button-${index}`}"
<span class="font-medium text-[22px]"> {faq.question} </span>
<span class="ml-6 h-7 flex items-center">
class="h-6 w-6 transform transition-transform duration-300 ease-in-out"
xmlns="http://www.w3.org/2000/svg"
class="mt-2 overflow-hidden transition-all duration-300 ease-in-out max-h-0"
aria-labelledby="{`faq-button-${index}`}"
<p class="text-base pt-3" set:html="{faq.answer}" />
document.addEventListener("DOMContentLoaded", () => {
const faqButtons = document.querySelectorAll(
".faq-accordion dt button",
let currentlyOpenContent: HTMLElement | null = null;
faqButtons.forEach((button) => {
button.addEventListener("click", () => {
const content = button.parentElement!
.nextElementSibling as HTMLElement;
button.getAttribute("aria-expanded") === "true"; // Close the currently open item if it's not the one being clicked
if (currentlyOpenContent && currentlyOpenContent !== content) {
currentlyOpenContent.previousElementSibling!.querySelector(
openButton.setAttribute("aria-expanded", "false");
.classList.remove("rotate-180");
currentlyOpenContent.style.maxHeight = "0";
} // Toggle the clicked item
button.setAttribute("aria-expanded", "true");
content.style.maxHeight = content.scrollHeight + "px";
currentlyOpenContent = content;
button.setAttribute("aria-expanded", "false");
content.style.maxHeight = "0";
currentlyOpenContent = null;
button.querySelector("svg")!.classList.toggle("rotate-180");