4

The product tabs on the product item page in Magento, how would I go making all the tabs collapsed by default on mobile view?

6

Create a copy of the core details file in your local theme: app/design/frontend/{Vendor}/{Theme}/Magento_Catalog/templates/product/view/details.phtml and remove the data-mage-init='{"tabs":{"openedState":"active"}}' and add the following:

<script type="text/javascript">
        require(['jquery', 'matchMedia', 'accordion'], function($, mediaCheck) {

            var detailsTabs = $('.product.data.items');

            mediaCheck({
                media: '(min-width: 768px)',
                // Switch to Desktop Version
                entry: function () {
                    detailsTabs.tabs({
                        openedState: "active",
                        collapsible: false
                    });
                },
                // Switch to Mobile Version
                exit: function () {
                    detailsTabs.tabs({
                        openedState: "active",
                        collapsible: true,
                        active: false
                    });
                }
            });
        })
</script>
2
  • Thanks @Stevie-Ray it helps me. Dec 16 '19 at 7:19
  • Thanks for the solution brother, It's worked but how to keep first tab is open on load in mobile view? Jun 24 at 15:34
0

extend tabs.js from magento core to set the option collapsible to true. I think that should collapse them by default.

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.