Skip to content

Commit

Permalink
Add tests for quick_tags and fix failing tags tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ringvold committed Dec 12, 2024
1 parent 3db95ff commit 995b45c
Show file tree
Hide file tree
Showing 4 changed files with 565 additions and 28 deletions.
6 changes: 2 additions & 4 deletions lib/live_select/component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,13 @@ defmodule LiveSelect.Component do
extra_params
)
when active_option >= 0 do
option = Enum.at(socket.assigns.options, active_option)
option = Enum.at(options, active_option)

if already_selected?(option, selection) do
pos = get_selection_index(option, selection)
unselect(socket, pos)
else
select(socket, Enum.at(socket.assigns.options, socket.assigns.active_option), extra_params)
select(socket, Enum.at(options, active_option), extra_params)
end
end

Expand Down Expand Up @@ -710,7 +710,6 @@ defmodule LiveSelect.Component do
defp next_selectable(%{
options: options,
active_option: active_option,
selection: selection,
mode: :quick_tags
}) do
options
Expand Down Expand Up @@ -739,7 +738,6 @@ defmodule LiveSelect.Component do
defp prev_selectable(%{
options: options,
active_option: active_option,
selection: selection,
mode: :quick_tags
}) do
options
Expand Down
18 changes: 10 additions & 8 deletions lib/live_select/component.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
data-field={@field.id}
data-debounce={@debounce}
>

<div class={
class(@style, :tags_container, @tags_container_class, @tags_container_extra_class)
}>
<div class={class(@style, :tags_container, @tags_container_class, @tags_container_extra_class)}>
<%= if (@mode == :tags || @mode == :quick_tags) && Enum.any?(@selection) do %>
<%= for {option, idx} <- Enum.with_index(@selection) do %>
<div class={class(@style, :tag, @tag_class, @tag_extra_class)}>
Expand Down Expand Up @@ -41,8 +38,8 @@
</button>
</div>
<% end %>
<% end %>
</div>
<% end %>
</div>

<div>
<%= text_input(@field.form, @text_input_field,
Expand Down Expand Up @@ -124,12 +121,17 @@
)
)
}
data-idx={idx}
data-idx={
if @mode == :quick_tags or not already_selected?(option, @selection), do: idx
}
>
<%= if @option == [] do %>
<%= option.label %>
<% else %>
<%= render_slot(@option, Map.merge(option, %{selected: already_selected?(option, @selection)})) %>
<%= render_slot(
@option,
Map.merge(option, %{selected: already_selected?(option, @selection)})
) %>
<% end %>
</div>
</li>
Expand Down
35 changes: 19 additions & 16 deletions lib/support/live_select_web/live/showcase_live.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,21 @@
value_mapper={&value_mapper/1}
{live_select_assigns(@settings_form.source)}
>
<:option :let={%{label: label, value: value, selected: selected}}>
<%= if @settings_form[:custom_option_html].value do %>
<div class="flex justify-content items-center">
<input
class="rounded w-4 h-4 mr-3 border border-border"
type="checkbox"
checked={selected}
/>
<span class="text-sm"><%= label %></span>
</div>
<% else %>
<%= label %>
<% end %>
</:option>
</.live_select>
<:option :let={%{label: label, value: _value, selected: selected}}>
<%= if @settings_form[:custom_option_html].value do %>
<div class="flex justify-content items-center">
<input
class="rounded w-4 h-4 mr-3 border border-border"
type="checkbox"
checked={selected}
/>
<span class="text-sm"><%= label %></span>
</div>
<% else %>
<%= label %>
<% end %>
</:option>
</.live_select>
</div>
<div class="flex flex-col gap-y-1">
{submit("Submit",
Expand Down Expand Up @@ -345,7 +345,10 @@
<.copy_to_clipboard_icon />
</button>
</div>
<Render.live_select custom_option_html={@settings_form[:custom_option_html].value} opts={Settings.live_select_opts(@settings_form.data, true)} />
<Render.live_select
custom_option_html={@settings_form[:custom_option_html].value}
opts={Settings.live_select_opts(@settings_form.data, true)}
/>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 995b45c

Please sign in to comment.