Close band dropdown after selection by shifting focus to map

This commit is contained in:
Graham McIntire 2026-03-31 09:04:31 -05:00
parent 97d4bd9372
commit b87572aa81
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59
2 changed files with 8 additions and 9 deletions

View file

@ -28,8 +28,8 @@ defmodule MicrowavepropWeb.MapLive do
end
@impl true
def handle_event("select_band", %{"value" => band_str}, socket) do
band = String.to_integer(band_str)
def handle_event("select_band", %{"value" => band}, socket) do
band = if is_binary(band), do: String.to_integer(band), else: band
scores = Propagation.latest_scores(band, socket.assigns.bounds)
socket =
@ -105,8 +105,10 @@ defmodule MicrowavepropWeb.MapLive do
>
<li :for={band <- @bands}>
<button
phx-click="select_band"
value={band.freq_mhz}
phx-click={
JS.push("select_band", value: %{value: band.freq_mhz})
|> JS.dispatch("click", to: "#propagation-map")
}
class={[if(@selected_band == band.freq_mhz, do: "active")]}
>
{band.label}

View file

@ -31,13 +31,10 @@ defmodule MicrowavepropWeb.MapLiveTest do
end
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")
html =
lv
|> element("button[value='24000']")
|> render_click()
html = render_click(lv, "select_band", %{"value" => 24_000})
assert html =~ "24 GHz"
end