Shopify themes, liquid, logos, and UX
I want the previously opened filter tab to close automatically when I open a new filter tab. I am using the Impact theme.
Website URL : https://myperfectwear.com/collections/journals-notebooks
Solved! Go to the solution
This is an accepted solution.
Hi @Digital_Imran,
I am from Mageplaza - Shopify solution expert.
To change the expand/collapse behavior of the filter in your Shopify store, you'll need to modify the CSS and JS in your theme. Here are some suggestions to help you achieve this:
2. Modify the JavaScript Code:
document.addEventListener('DOMContentLoaded', function () {
const filterHeaders = document.querySelectorAll('.filter-tab-header'); // Adjust selector based on your theme
filterHeaders.forEach((header) => {
header.addEventListener('click', () => {
// Close all other filter tabs
filterHeaders.forEach((otherHeader) => {
if (otherHeader !== header) {
const otherContent = otherHeader.nextElementSibling; // Adjust based on your theme structure
if (otherContent && otherContent.classList.contains('open')) {
otherContent.classList.remove('open');
otherContent.style.height = 0; // Collapses the content
}
}
});
// Toggle the clicked tab
const content = header.nextElementSibling; // Adjust based on your theme structure
if (content) {
const isOpen = content.classList.contains('open');
content.style.height = isOpen ? 0 : `${content.scrollHeight}px`;
content.classList.toggle('open');
}
});
});
});
3. Add Necessary CSS:
Ensure the filter tabs respond visually when opened or closed. Add this to your CSS file (e.g., theme.css or base.css):
.filter-tab-content {
overflow: hidden;
height: 0;
transition: height 0.3s ease;
}
.filter-tab-content.open {
height: auto;
}
4. Save and test:
I hope this helps, please leave a comment if you need further instructions !
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
This is an accepted solution.
Hi @Digital_Imran,
I am from Mageplaza - Shopify solution expert.
To change the expand/collapse behavior of the filter in your Shopify store, you'll need to modify the CSS and JS in your theme. Here are some suggestions to help you achieve this:
2. Modify the JavaScript Code:
document.addEventListener('DOMContentLoaded', function () {
const filterHeaders = document.querySelectorAll('.filter-tab-header'); // Adjust selector based on your theme
filterHeaders.forEach((header) => {
header.addEventListener('click', () => {
// Close all other filter tabs
filterHeaders.forEach((otherHeader) => {
if (otherHeader !== header) {
const otherContent = otherHeader.nextElementSibling; // Adjust based on your theme structure
if (otherContent && otherContent.classList.contains('open')) {
otherContent.classList.remove('open');
otherContent.style.height = 0; // Collapses the content
}
}
});
// Toggle the clicked tab
const content = header.nextElementSibling; // Adjust based on your theme structure
if (content) {
const isOpen = content.classList.contains('open');
content.style.height = isOpen ? 0 : `${content.scrollHeight}px`;
content.classList.toggle('open');
}
});
});
});
3. Add Necessary CSS:
Ensure the filter tabs respond visually when opened or closed. Add this to your CSS file (e.g., theme.css or base.css):
.filter-tab-content {
overflow: hidden;
height: 0;
transition: height 0.3s ease;
}
.filter-tab-content.open {
height: auto;
}
4. Save and test:
I hope this helps, please leave a comment if you need further instructions !
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025