Components
41
Accordion Block Benifits Grid Block 404 Card Stack Careers Grid Case Study Carousel Case Study Hero Content Columns Content Image Content Image Accordion Content Video Cta Block Example Featured Blog Hero Featured Resource Hero Form Cta Form Hero Full Width Image Homepage Hero Hover List Image Hero Image Mask Image Testimonial Carousel Industry Insights Latest News List Columns Logo Scroller Map Block Post Feed Resource Grid Split Hero Split Text Statement Statistics Row Team Filter Team Grid Testimonial Carousel Testimonial Carousel Text Highlight Tools Grid Two Column List

Accordion Block

View example
There are no ACF fields assigned to this component.

				
There are is no SCSS file with this component.
class AccordionBlock {
    /**
     * Create and initialise objects of this class
     * @param {object} block
     */
    constructor(block) {
        this.block = block;
        this.items = block.querySelectorAll('.qa-item');
        this.init();
    }

    init() {
        this.items.forEach(item => {
            const trigger = item.querySelector('.qa-item-trigger');
            const content = item.querySelector('.qa-item-content');

            trigger.addEventListener('click', () => {
                // Toggle
                const isOpen = item.classList.contains('is-open');
                this.closeAll();

                if (!isOpen) {
                    item.classList.add('is-open');
                    content.style.maxHeight = content.scrollHeight + 50 + 'px';
                }
            });
        });
    }

    closeAll() {
        this.items.forEach(item => {
            item.classList.remove('is-open');
            const content = item.querySelector('.qa-item-content');
            content.style.maxHeight = '0px';
        });
    }
}

document.addEventListener('DOMContentLoaded', () => {
    document.querySelectorAll('.block-accordion-block').forEach(
        block => new AccordionBlock(block)
    );
});
{
    "$schema": "https://schemas.wp.org/trunk/block.json",
    "apiVersion": 2,
    "name": "strategiq/accordion-block",
    "title": "Accordion Block",
    "description": "Accordion Block",
    "category": "strategiq",
    "icon": "strategiq",
    "acf": {
        "mode": "preview",
        "renderTemplate": "block-accordion.php"
    },
    "supports": {
        "anchor": true,
        "align": false,
        "color": {
            "background": true,
            "text": false,
            "gradients": false
        },
        "spacing": {
            "padding": [
                "top",
                "bottom"
            ],
            "margin": [
                "top",
                "bottom"
            ]
        }
    },
    "style": "file:../../assets/css/accordion-block/block-accordion.css"
}
Page Title
Page Type
Page URL
SEO A-Z Guide
landing_pages
There are is no readme file with this component.