From 597df89b4153fac5042a291d4cfc66a439e0a05d Mon Sep 17 00:00:00 2001 From: Pete Lacey Date: Tue, 19 Apr 2022 15:08:06 -0700 Subject: [PATCH] Fix 'navigate' link to use live_redirect and support keyboard navigation --- lib/live_beats_web/live/live_helpers.ex | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/live_beats_web/live/live_helpers.ex b/lib/live_beats_web/live/live_helpers.ex index 2dc8eb5..fbfe704 100644 --- a/lib/live_beats_web/live/live_helpers.ex +++ b/lib/live_beats_web/live/live_helpers.ex @@ -122,13 +122,17 @@ defmodule LiveBeatsWeb.LiveHelpers do """ end - def link(%{navigate: _to} = assigns) do - assigns = assign_new(assigns, :class, fn -> nil end) + def link(%{navigate: to} = assigns) do + opts = + assigns + |> assign_new(:class, fn -> nil end) + |> assigns_to_attributes([:navigate]) + |> Keyword.put(:to, to) + + assigns = assign(assigns, :opts, opts) ~H""" - - <%= render_slot(@inner_block) %> - + <%= live_redirect @opts do %><%= render_slot(@inner_block) %><% end %> """ end