Skip to content

Joomla 5 Bootstrap Collapse Not Working on Frontend -- The Real Fix

More
3 weeks 54 minutes ago #828 by admin
You add data-bs-toggle="collapse" to a button in Joomla 5, point it at a target div, and... nothing. The button renders, looks correct, but clicking it does absolutely nothing. No error, no animation, nothing.

This trips up everyone who's used Bootstrap 5 on a normal site, because Joomla 5's Bootstrap works differently.

Symptoms
  • data-bs-toggle="collapse" buttons don't respond to clicks
  • Accordion components don't expand/collapse
  • Smart Search advanced filter toggle does nothing
  • No JavaScript errors in the console
  • The same markup works perfectly on a regular Bootstrap 5 site

Root Cause

Joomla 5 loads Bootstrap JS as ES modules, not as a global script. This means:

1. window.bootstrap does not exist -- you can't call new bootstrap.Collapse()
2. Standard data-attribute auto-initialization is disabled -- Joomla stripped Bootstrap's document-level click delegation
3. Instead, Joomla uses Joomla.getOptions("bootstrap.collapse") to get a list of specific element IDs to initialize

If your element isn't registered in that options JSON, Bootstrap's collapse JS never touches it. The button just sits there doing nothing.

This is why Smart Search's Advanced Search toggle is broken out of the box -- the com_finder component adds the markup but doesn't register the element in Joomla.getOptions().

The Fix

Add a click handler in your template's JavaScript that targets all collapse triggers:
Code:
document.querySelectorAll('[data-bs-toggle="collapse"]').forEach(function(btn) { btn.addEventListener('click', function(e) { e.preventDefault(); var targetSel = btn.getAttribute('data-bs-target') || btn.getAttribute('href'); var target = document.querySelector(targetSel); if (!target) return; if (target.classList.contains('show')) { target.style.height = target.scrollHeight + 'px'; target.offsetHeight; // force reflow target.classList.add('collapsing'); target.classList.remove('collapse', 'show'); target.style.height = '0'; target.addEventListener('transitionend', function handler() { target.classList.remove('collapsing'); target.classList.add('collapse'); target.style.height = ''; target.removeEventListener('transitionend', handler); }); } else { target.classList.remove('collapse'); target.classList.add('collapsing'); target.style.height = '0'; target.offsetHeight; // force reflow target.style.height = target.scrollHeight + 'px'; target.addEventListener('transitionend', function handler() { target.classList.remove('collapsing'); target.classList.add('collapse', 'show'); target.style.height = ''; target.removeEventListener('transitionend', handler); }); } }); });

You also need these CSS classes (Joomla doesn't load Bootstrap's CSS on the frontend):
Code:
.collapse:not(.show) { display: none; } .collapsing { height: 0; overflow: hidden; transition: height .35s ease; }

[hr]
This is one of 65+ gotchas documented in The AI Joomla Blueprint -- theaidirector.win

Please Log in or Create an account to join the conversation.

Time to create page: 0.217 seconds

The AI Director

Enjoy Building Joomla Sites with AI

The most enjoyable way to build a Joomla site. Open it in VS Code → — describe what you want, Claude Code → reads the briefing, runs the stack, writes the code. You just keep the conversation going.

A new paradigm.

Browse the Shop →
Built & designed by Weblio Sites from 9 900 NOK — built to outperform

This site was designed and built by Weblio — a Norwegian web agency specialising in fast, professional websites and AI-powered tools for businesses that want to move faster than their competition. Direct communication, honest pricing, no surprises.

Visit Weblio.no →