- <%= if (@mode == :tags || @mode == :quick_tags) && Enum.any?(@selection) do %>
+ <%= if (@mode in [:tags, :quick_tags]) && Enum.any?(@selection) do %>
<%= for {option, idx} <- Enum.with_index(@selection) do %>
<%= if @tag == [] do %>
diff --git a/lib/support/live_select_web/live/showcase_live.ex b/lib/support/live_select_web/live/showcase_live.ex
index 24210ad..bfa397d 100644
--- a/lib/support/live_select_web/live/showcase_live.ex
+++ b/lib/support/live_select_web/live/showcase_live.ex
@@ -67,7 +67,7 @@ defmodule LiveSelectWeb.ShowcaseLive do
field(:allow_clear, :boolean)
field(:debounce, :integer, default: Component.default_opts()[:debounce])
field(:disabled, :boolean)
- field(:custom_option_html, :boolean)
+ field(:options_styled_as_checkboxes, :boolean)
field(:max_selectable, :integer, default: Component.default_opts()[:max_selectable])
field(:user_defined_options, :boolean)
@@ -99,7 +99,7 @@ defmodule LiveSelectWeb.ShowcaseLive do
:allow_clear,
:debounce,
:disabled,
- :custom_option_html,
+ :options_styled_as_checkboxes,
:max_selectable,
:user_defined_options,
:mode,
@@ -126,7 +126,7 @@ defmodule LiveSelectWeb.ShowcaseLive do
default_opts = Component.default_opts()
settings
- |> Map.drop([:search_delay, :new, :selection, :custom_option_html])
+ |> Map.drop([:search_delay, :new, :selection, :options_styled_as_checkboxes])
|> Map.from_struct()
|> then(
&if is_nil(&1.style) do
@@ -260,7 +260,7 @@ defmodule LiveSelectWeb.ShowcaseLive do
assigns = assign(assigns, opts: opts, format_value: format_value)
~H"""
- <%= if @custom_option_html do %>
+ <%= if @options_styled_as_checkboxes do %>
<.live_select
field={my_form[:city_search]}
@@ -341,6 +341,17 @@ defmodule LiveSelectWeb.ShowcaseLive do
socket
end
+ params =
+ if params["mode"] == "quick_tags" do
+ Map.put_new(
+ params,
+ "selected_option_class",
+ "cursor-pointer font-bold hover:bg-gray-400 rounded"
+ )
+ else
+ params
+ end
+
changeset =
Settings.changeset(params)
|> then(
@@ -355,16 +366,9 @@ defmodule LiveSelectWeb.ShowcaseLive do
{:ok, settings} ->
socket.assigns
- attrs =
- if settings.mode == :quick_select do
- %{selected_option_class: "cursor-pointer font-bold hover:bg-gray-400 rounded"}
- else
- %{}
- end
-
socket =
socket
- |> assign(:settings_form, Settings.changeset(settings, attrs) |> to_form)
+ |> assign(:settings_form, Settings.changeset(settings, %{}) |> to_form)
|> update(:schema_module, fn _, %{settings_form: settings_form} ->
if settings_form[:mode].value == :single, do: CitySearchSingle, else: CitySearchMany
end)
diff --git a/lib/support/live_select_web/live/showcase_live.html.heex b/lib/support/live_select_web/live/showcase_live.html.heex
index 32a7a92..1e9b1cf 100644
--- a/lib/support/live_select_web/live/showcase_live.html.heex
+++ b/lib/support/live_select_web/live/showcase_live.html.heex
@@ -72,8 +72,8 @@
{checkbox(@settings_form, :disabled, class: "toggle")}
<% end %>
<%= label class: "label cursor-pointer" do %>
- Custom option HTML:
- <%= checkbox(@settings_form, :custom_option_html, class: "toggle") %>
+ Options styles as checkboxes:
+ <%= checkbox(@settings_form, :options_styled_as_checkboxes, class: "toggle") %>
<% end %>
diff --git a/test/live_select/component_test.exs b/test/live_select/component_test.exs
index c36a49e..463e7d4 100644
--- a/test/live_select/component_test.exs
+++ b/test/live_select/component_test.exs
@@ -539,11 +539,6 @@ defmodule LiveSelect.ComponentTest do
]
end
- describe "in quick_tags mode" do
- test "" do
- end
- end
-
for style <- [:daisyui, :tailwind, :none, nil] do
@style style