Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/live_select.ex
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,12 @@ defmodule LiveSelect do
doc:
"one of `:tailwind`, `:daisyui` or `:none`. See the [Styling section](styling.html) for details"

attr :tags_container_position, :atom,
values: [:top, :bottom],
default: Component.default_opts()[:tags_container_position],
doc:
"used to set the position of the tags container. One of `:top` or `:bottom` to show the tags container at the top or bottom of the dropdown"

slot(:option,
doc:
"optional slot that renders an option in the dropdown. The option's data is available via `:let`"
Expand Down
1 change: 1 addition & 0 deletions lib/live_select/component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ defmodule LiveSelect.Component do
tag_extra_class: nil,
tags_container_class: nil,
tags_container_extra_class: nil,
tags_container_position: :top,
text_input_class: nil,
text_input_extra_class: nil,
text_input_selected_class: nil,
Expand Down
102 changes: 72 additions & 30 deletions lib/live_select/component.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,43 @@
data-field={@field.id}
data-debounce={@debounce}
>
<div class={class(@style, :tags_container, @tags_container_class, @tags_container_extra_class)}>
<%= if (@mode in [:tags, :quick_tags]) && Enum.any?(@selection) do %>
<%= for {option, idx} <- Enum.with_index(@selection) do %>
<div class={class(@style, :tag, @tag_class, @tag_extra_class)}>
<%= if @tag == [] do %>
<%= option[:tag_label] || option[:label] %>
<% else %>
<%= render_slot(@tag, option) %>
<% end %>
<button
:if={!option[:sticky] && !@disabled}
type="button"
data-idx={idx}
class={
class(
@style,
:clear_tag_button,
@clear_tag_button_class,
@clear_tag_button_extra_class
) ++
if @no_basic_styles_for_clear_buttons, do: [], else: ~w(ls-clear-tag-button)
}
>
<%= if @clear_button == [] do %>
<.x />
<%= if @tags_container_position == :top do %>
<div class={
class(@style, :tags_container, @tags_container_class, @tags_container_extra_class)
}>
<%= if (@mode in [:tags, :quick_tags]) && Enum.any?(@selection) do %>
<%= for {option, idx} <- Enum.with_index(@selection) do %>
<div class={class(@style, :tag, @tag_class, @tag_extra_class)}>
<%= if @tag == [] do %>
<%= option[:tag_label] || option[:label] %>
<% else %>
<%= render_slot(@clear_button) %>
<%= render_slot(@tag, option) %>
<% end %>
</button>
</div>
<button
:if={!option[:sticky] && !@disabled}
type="button"
data-idx={idx}
class={
class(
@style,
:clear_tag_button,
@clear_tag_button_class,
@clear_tag_button_extra_class
) ++
if @no_basic_styles_for_clear_buttons, do: [], else: ~w(ls-clear-tag-button)
}
>
<%= if @clear_button == [] do %>
<.x />
<% else %>
<%= render_slot(@clear_button) %>
<% end %>
</button>
</div>
<% end %>
<% end %>
<% end %>
</div>
</div>
<% end %>

<div>
<%= text_input(@field.form, @text_input_field,
Expand Down Expand Up @@ -150,4 +154,42 @@
<% end %>
</ul>
<% end %>

<%= if @tags_container_position == :bottom do %>
<div class={
class(@style, :tags_container, @tags_container_class, @tags_container_extra_class)
}>
<%= if (@mode in [:tags, :quick_tags]) && Enum.any?(@selection) do %>
<%= for {option, idx} <- Enum.with_index(@selection) do %>
<div class={class(@style, :tag, @tag_class, @tag_extra_class)}>
<%= if @tag == [] do %>
<%= option[:tag_label] || option[:label] %>
<% else %>
<%= render_slot(@tag, option) %>
<% end %>
<button
:if={!option[:sticky] && !@disabled}
type="button"
data-idx={idx}
class={
class(
@style,
:clear_tag_button,
@clear_tag_button_class,
@clear_tag_button_extra_class
) ++
if @no_basic_styles_for_clear_buttons, do: [], else: ~w(ls-clear-tag-button)
}
>
<%= if @clear_button == [] do %>
<.x />
<% else %>
<%= render_slot(@clear_button) %>
<% end %>
</button>
</div>
<% end %>
<% end %>
</div>
<% end %>
</div>
Loading