Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Accordion default open items

  • Hi there,

    I love the new tabs and accordion in Generate press. I have one question. I want all items of the accordion open on desktop (using default settings) and closed on mobile. Is this possible? The current default setting is for all screen sizes.

    Regards,
    Martijn

  • Hi there,

    thanks for the kind words 🙂

    Can i see what you have so far on your site ? It may be possible with a little extra JS.

  • Hi David, great. I’ve added login details for the website (that’s work in progress) below.

    Regards,
    Martijn

  • You could try some JS to “click” on each accordion item after to load to open them all and only on larger screens:

    <script>
    const accordionItems = document.querySelectorAll('.gb-accordion__item');
    
    if (window.innerWidth >= 768) {
      accordionItems.forEach((item) => {
        const clickEvent = new MouseEvent('click', {
          view: window,
          bubbles: true,
          cancelable: true
        });
    
        // Dispatch the click event on the accordion item element
        item.dispatchEvent(clickEvent);
      });
    }
    </script>
  • Hi David,

    Thanks. But I can’t get it to work properly. I’ve added the script to the page (template).
    My accordion items are currently open by default on the desktop and I hide the accordion title on desktop.

    Am I missing something?

    Kind regards,
    Martijn

  • Ooh.. I didn’t realise the entire page were accordions.
    Ok, remove the script I provided.

    Then set all the items to be closed by default.
    We can then use some CSS on desktop only to force them ALL to be open.

  • Hi David.

    No problem. Could you give me a hint on how to open them by CSS?

    Regards,
    Martijn

  • Something like this:

    @media(min-width: 769px) {
        .open-on-desktop  .gb-accordion__content {
            max-height: inherit !important;
        }
    }

    And select the Accordion Items Block and give it a class of: open-on-desktop

    If that don’t work, then close the accordions on desktop and let me know

  • Hi David.

    Thank you very much.

    All accordion items block settings disabled -item default open- and are now opened on desktop by default and closed on mobile, as intended. It works perfectly.

    Excellent support, as always. I learned a lot. I did not know that opening and closing the accordion items could be solved even with CSS instead of javascript.

    Sincerely,
    Martijn

  • Awesome
    Glad to be of help 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.