CombBox bugfix: stale spinner on creatable options selection (#3713)

This commit is contained in:
hq1 2024-01-22 15:32:11 +01:00 committed by GitHub
parent 6ca4eaf5e2
commit 36a8b36382
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -243,7 +243,7 @@ defmodule PlausibleWeb.Live.Components.ComboBox do
> >
<a <a
x-ref={"dropdown-#{@ref}-option-#{@idx}"} x-ref={"dropdown-#{@ref}-option-#{@idx}"}
x-on:click="selectionInProgress = true" x-on:click={not @creatable && "selectionInProgress = true"}
phx-click={select_option(@ref, @submit_value, @display_value)} phx-click={select_option(@ref, @submit_value, @display_value)}
phx-value-submit-value={@submit_value} phx-value-submit-value={@submit_value}
phx-value-display-value={@display_value} phx-value-display-value={@display_value}

View File

@ -274,6 +274,20 @@ defmodule PlausibleWeb.Live.Components.ComboBoxTest do
"input[type=hidden][name=some_submit_name][value=\"my new option\"]" "input[type=hidden][name=some_submit_name][value=\"my new option\"]"
) )
end end
test "selectionInProgress doesn't apply when no server roundtrip is needed", %{conn: conn} do
{:ok, lv, html} = live_isolated(conn, CreatableView, session: %{})
regular_option = find(html, "li#dropdown-test-creatable-component-option-1 a")
assert Floki.attribute(regular_option, "x-on:click") == ["selectionInProgress = true"]
creatable_option =
lv
|> type_into_combo("test-creatable-component", "my new option")
|> find("input[type=hidden][name=some_submit_name][value=\"my new option\"]")
assert Floki.attribute(creatable_option, "x-on:click") == []
end
end end
describe "async suggestions" do describe "async suggestions" do