jmnda

jmnda

Am using tailwind CSS and Flowbite component library. However what’s happening is that when loading a LiveView page and interact with a Flowbite component like a Modal, it’s working fine, but if I redirect to another LiveView and back to the same page, the Modal stops working. This applies to all elements that require Flowbite javascript for interaction like Accordions, Modals, Sidebars e.t.c. I tried to use CDN’s since configuring tailwind in my phoenix project was not working as well. Even after adding CDN’s, the problem still persists. Here is what I added to root.html.heex

<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://unpkg.com/flowbite@1.5.3/dist/flowbite.min.css" />

<body>
. . . 

<script src="https://unpkg.com/flowbite@1.5.3/dist/flowbite.js"></script>
</body>

But when I use Bootstrap CSS and JS CDN’s, all the bootstrap components that use javascript work fine even if I navigate between LiveViews. Not sure what’s going on but need help ASAP.

Showing Posts 1 to 10

egze

egze

Can you create a demo repo to reproduce? Otherwise, it’s hard to help.

jmnda

jmnda OP

I have created a demo repo, you can switch between main and bootstrap branches to test things out and understand what am talking about. Thanks.
https://github.com/jmnda-dev/demo-repo

egze

egze

  1. The repo only has 1 branch main. Did you forget to push the other one?
  2. For me, it works, clicking between liveviews and modals always work and also accordions. Is there anything specific I need to do to reproduce it? Record a video, maybe.
jmnda

jmnda OP

Oh I forgot. Let me push it and create a gif

jmnda

jmnda OP

I push the branch. I have added a gif to the repo Readme since the gif was too large to upload here

egze

egze

Flowbite inits the objects when the DOM loads (DOMContentLoaded event). With live navigation, this event doesn’t fire anymore, that’s why on next LiveView it stops working.

What you can do as a quick fix, is listen to LiveView events and dispatch the DOMContentLoaded event yourself, to trick Flowbite.

Put this in your app.js

window.addEventListener('phx:page-loading-stop', (event) => {
  // trigger flowbite events
  window.document.dispatchEvent(new Event("DOMContentLoaded", {
    bubbles: true,
    cancelable: true
  }));
});
jmnda

jmnda OP

I have tried it, but unfortunately, it has not worked. I even tried adding phx-click={JS.dispatch("DOMContentLoaded")} to a button, the event was successfully being dispatched but still the flowbite components won’t work

egze

egze

Did you try the exact code I wrote? Because it works for me.

I can send a PR if you want

jmnda

jmnda OP

Yeah, I tried the exact code. A PR is welcome :blush:. Maybe am doing something wrong

jmnda

jmnda OP

Actually, it’s working. I didn’t realize I was testing it in the actual project and was not working, but it’s working it the repo I shared. I have also discovered that it’s only working when I add Flowbite via a CDN script tag, but not when I install it as a node_module and import it in app.js and add it to tailwind.config.js plugins. and content. Thanks very much for the help. For now, I will just work with the CDN and figure out the rest later

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews