Fix 'navigate' link to use live_redirect and support keyboard navigation

This commit is contained in:
Pete Lacey 2022-04-19 15:08:06 -07:00
parent f1908151f9
commit 597df89b41

View file

@ -122,13 +122,17 @@ defmodule LiveBeatsWeb.LiveHelpers do
""" """
end end
def link(%{navigate: _to} = assigns) do def link(%{navigate: to} = assigns) do
assigns = assign_new(assigns, :class, fn -> nil end) opts =
assigns
|> assign_new(:class, fn -> nil end)
|> assigns_to_attributes([:navigate])
|> Keyword.put(:to, to)
assigns = assign(assigns, :opts, opts)
~H""" ~H"""
<a href={@navigate} data-phx-link="redirect" data-phx-link-state="push" class={@class}> <%= live_redirect @opts do %><%= render_slot(@inner_block) %><% end %>
<%= render_slot(@inner_block) %>
</a>
""" """
end end