Auto Collapsed all tabs by defualt similar to accordion

I’ve done this.

Method one - closed by default (with bricks):

  1. Assign a class to your tabs and the pane
  2. remove the class on load with bricks interaction
    This will prevent the tabs from being open on page load.

Method two - closed by default (with jQuery):

  1. These lines will do it
jQuery(document).ready(function($) {

        var tabTitle = '.mly-product-tabs__title';
        var tabPane = '.mly-product-tabs__pane';

        $(tabTitle + ', ' + tabPane).removeClass('brx-open');
});




Closed by default and close on click
Now that you want the tabs to close again on click i recommend to use the below only so you don’t mix’n’match interactions in bricks with code. Can be difficult to maintain and remember.

jQuery(document).ready(function($) {
    var hadClassInitially = false,
        tabTitle = '.mly-product-tabs__title',
        tabPane = '.mly-product-tabs__pane';

        $(tabTitle + ', ' + tabPane).removeClass('brx-open');

    // Capture the initial state using mousedown
    $(document).on('mousedown', tabTitle, function() {
        hadClassInitially = $(this).hasClass('brx-open');
    });

    // Perform the action based on the captured state using click
    $(document).on('click', tabTitle, function() {
        if (hadClassInitially) {
            // Remove the 'brx-open' class from both 'tab-title' and 'tab-pane'
            $(tabTitle + ', ' + tabPane).removeClass('brx-open');
        }
    });
});


2 Likes