Close band dropdown after selection by shifting focus to map
This commit is contained in:
parent
97d4bd9372
commit
b87572aa81
2 changed files with 8 additions and 9 deletions
|
|
@ -28,8 +28,8 @@ defmodule MicrowavepropWeb.MapLive do
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_event("select_band", %{"value" => band_str}, socket) do
|
def handle_event("select_band", %{"value" => band}, socket) do
|
||||||
band = String.to_integer(band_str)
|
band = if is_binary(band), do: String.to_integer(band), else: band
|
||||||
scores = Propagation.latest_scores(band, socket.assigns.bounds)
|
scores = Propagation.latest_scores(band, socket.assigns.bounds)
|
||||||
|
|
||||||
socket =
|
socket =
|
||||||
|
|
@ -105,8 +105,10 @@ defmodule MicrowavepropWeb.MapLive do
|
||||||
>
|
>
|
||||||
<li :for={band <- @bands}>
|
<li :for={band <- @bands}>
|
||||||
<button
|
<button
|
||||||
phx-click="select_band"
|
phx-click={
|
||||||
value={band.freq_mhz}
|
JS.push("select_band", value: %{value: band.freq_mhz})
|
||||||
|
|> JS.dispatch("click", to: "#propagation-map")
|
||||||
|
}
|
||||||
class={[if(@selected_band == band.freq_mhz, do: "active")]}
|
class={[if(@selected_band == band.freq_mhz, do: "active")]}
|
||||||
>
|
>
|
||||||
{band.label}
|
{band.label}
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,10 @@ defmodule MicrowavepropWeb.MapLiveTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "select_band" do
|
describe "select_band" do
|
||||||
test "updates selected band on click", %{conn: conn} do
|
test "updates selected band on event", %{conn: conn} do
|
||||||
{:ok, lv, _html} = live(conn, ~p"/map")
|
{:ok, lv, _html} = live(conn, ~p"/map")
|
||||||
|
|
||||||
html =
|
html = render_click(lv, "select_band", %{"value" => 24_000})
|
||||||
lv
|
|
||||||
|> element("button[value='24000']")
|
|
||||||
|> render_click()
|
|
||||||
|
|
||||||
assert html =~ "24 GHz"
|
assert html =~ "24 GHz"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue