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.
Trending in Questions
Other Trending Topics
Latest Phoenix Threads
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
egze
Can you create a demo repo to reproduce? Otherwise, it’s hard to help.
jmnda
I have created a demo repo, you can switch between
mainandbootstrapbranches to test things out and understand what am talking about. Thanks.https://github.com/jmnda-dev/demo-repo
egze
main. Did you forget to push the other one?jmnda
Oh I forgot. Let me push it and create a gif
jmnda
I push the branch. I have added a gif to the repo Readme since the gif was too large to upload here
egze
Flowbite inits the objects when the DOM loads (
DOMContentLoadedevent). 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
DOMContentLoadedevent yourself, to trick Flowbite.Put this in your
app.jsjmnda
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 workegze
Did you try the exact code I wrote? Because it works for me.
I can send a PR if you want
jmnda
Yeah, I tried the exact code. A PR is welcome
. Maybe am doing something wrong
jmnda
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_moduleand import it inapp.jsand add it totailwind.config.jsplugins. andcontent. Thanks very much for the help. For now, I will just work with the CDN and figure out the rest later