Skip to content

active tab attribute does not dynamically update tabs current active tab #472

@tanguilp

Description

@tanguilp

Hi again,

I want to use some links to patch my LiveView with the tab as a parameter:

  @impl true
  def handle_params(params, _uri, socket) do
    {:noreply, assign(socket, :amenity_type, params["amenity"])}
  end

and then using this assign in tabs with the active attribute:

        <:tab
          icon="hero-squares-2x2"
          active={@amenity_type == "shop"}
          on_select={JS.patch(~p"/some/path?amenity=shop")}
        >
        </:tab>
        <:tab
          icon="hero-xyz"
          active={@amenity_type == "restaurant"}
          on_select={JS.patch(~p"/some/path?amenity=restaurant")}
        >
        </:tab>

So far, so good. It works.

But when I patch from another place in the page, for example:

<.link patch={~p"/some/path?amenity=restaurant"}>
Go to restaurants
</.link>

then nothing happens: the current tab stays the same.

In other words active seems to work only on initial rendering, then it becomes dead. Is that the normal behaviour?

I know about VoyageeWeb.Components.Tabs.show_tab/3 but i'D prefer not to use it and rely on active only.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions