stabilow

stabilow

Tailwind Element component disappears after Phoenix LiveView socket connection

Hello all,

I am new to Phoenix and web development (but love both of them).

I am writing a toy application and decided to use https://tailwind-elements.com that provides me with some cool components.

I successfully managed to install the library and use it in my app.
However, I encountered a small issue and I have some difficulties to fix it. Maybe you could give me a hand! :slight_smile:

The issue is the following. I am working within a LiveView, and use the video carousel basic example from https://tailwind-elements.com/docs/standard/components/video-carousel. Once the LiveView’s socket is connected, the carousel disappears. If I remove the line liveSocket.connect(); from my app.js then everything works fine.

Do you have any idea ?

Thank you in advance !

Best

Marked As Solved

benstepp

benstepp

I’m not too sure how the library works, but you should be able to use a phx-hook for this, something like:

# app.js
import {Carousel, initTE} from 'tw-elements'

const Hooks = {}
Hooks.Carousel = {
  mounted() {
    initTE({ Carousel })
  }
}

let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket("/live", Socket, {hooks: Hooks, params: {_csrf_token: csrfToken}})
<div
  id="carouselExampleCaptions"
  phx-hook="Carousel"
  class="relative"
  data-te-carousel-init
  data-te-ride="carousel">

Last Post!

elvanja

elvanja

@stabilow how did you manage to install tw-elements?

I did:

  • npm install tw-elements --save in assets folder
  • added "./node_modules/tw-elements/dist/js/**/*.js", to tailwind config
  • and require("tw-elements/dist/plugin") in plugins

But I keep getting Error: Cannot find module '@tailwindcss/forms' which is strange. Also, when tw-elements stuff is removed, that line does not fail.

Thank you for your time!
P.S. Maybe better open a new thread?

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49084 226
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement