Dynamic css classes in function components with live_view 0.17.1

Hi, I have an issue with dynamic css classes after upgrading from live_view 0.16 to 0.17. I have a function component for a navigation bar entry like this:

 def nav_item_path(assigns) do
    ~H"""
    <li class={"nav-item #{if @conn.request_path == @route, do: "active"}"}>
      <%=  link to: @route, class: "nav-link"  do %>
        <%= if assigns[:icon] do %><i class="material-icons"><%= @icon %></i><% end %>
        <%= if assigns[:title] do %><p><%= @title %></p><% end %>
      <% end %>
    </li>
    """
  end

As you can see, the active css class is set dynamically. It worked fine with 0.16 but after upgrading the generated HTML looks like:

<li class="nav-item <i class=" material-icons"="">device_hub"&gt;
  <a class="nav-link" href="/admin/***/****">
    <i class="material-icons">device_hub</i>
    ******
  </a>
</li>

Am I using it wrong? Is there a better way to achieve this?
Additional information: I use this component in a dead view.

1 Like

Looks like a bug to me. I will investigate.

1 Like

Thanks a lot :slight_smile:

Fixed in master. Please give it a try and we can cut another release later. :slight_smile:

2 Likes

Like a charm :heart:
Thank you for the fast response and solution :slight_smile:

1 Like