Skip to content

Commit 0065b1c

Browse files
committed
Improve dropdown components and bump version to 0.1.7
- Remove fixed width constraints from select dropdowns for dynamic sizing - Add clear button (X) outside dropdown for better UX in Select component - Adjust dropdown alignment from end to start for consistency - Fix padding adjustment when clearable option is active - Continue CSS-based icon approach for better performance - Improve clear selection text and icon in dropdown menu Closes #1, #2, #3
1 parent 89cbc1d commit 0065b1c

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Add to your `mix.exs`:
2222
```elixir
2323
def deps do
2424
[
25-
{:livefilter, "~> 0.1.6"}
25+
{:livefilter, "~> 0.1.7"}
2626
]
2727
end
2828
```

lib/live_filter/components/search_select.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ defmodule LiveFilter.Components.SearchSelect do
8080
</.button>
8181
</.dropdown_menu_trigger>
8282
83-
<.dropdown_menu_content align="start" class="w-[280px] p-0">
83+
<.dropdown_menu_content align="start" class="p-0">
8484
<div :if={@searchable} class="p-2 pb-0">
8585
<div class="relative">
8686
<.icon

lib/live_filter/components/select.ex

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ defmodule LiveFilter.Components.Select do
1111
use Phoenix.Component
1212
import SaladUI.DropdownMenu
1313
import SaladUI.Button
14-
import SaladUI.Icon
1514
import SaladUI.Separator
1615

1716
@doc """
@@ -49,23 +48,24 @@ defmodule LiveFilter.Components.Select do
4948

5049
def select(assigns) do
5150
~H"""
52-
<div id={"#{@id}-wrapper"}>
51+
<div id={"#{@id}-wrapper"} class="relative inline-flex items-center">
5352
<.dropdown_menu id={@id}>
5453
<.dropdown_menu_trigger>
5554
<.button
5655
variant="outline"
5756
size={@size}
5857
class={[
5958
@class,
60-
"gap-1 items-center"
59+
"gap-1 items-center",
60+
@clearable && @selected && "pr-8"
6161
]}
6262
>
63-
<.icon :if={@icon} name={@icon} class="h-4 w-4" />
63+
<span :if={@icon} class={[@icon, "h-4 w-4"]} />
6464
{render_button_content(assigns)}
6565
</.button>
6666
</.dropdown_menu_trigger>
6767
68-
<.dropdown_menu_content align="end" class="w-[200px]">
68+
<.dropdown_menu_content align="start">
6969
<%= for {value, label} <- @options do %>
7070
<.dropdown_menu_item
7171
phx-click={@on_change}
@@ -74,23 +74,35 @@ defmodule LiveFilter.Components.Select do
7474
>
7575
<span>{label}</span>
7676
<%= if @selected == value do %>
77-
<.icon name="hero-check" class="ml-auto h-4 w-4" />
77+
<span class="hero-check ml-auto h-4 w-4" />
7878
<% end %>
7979
</.dropdown_menu_item>
8080
<% end %>
8181
8282
<%= if @clearable && @selected do %>
83-
<.dropdown_menu_separator />
83+
<.dropdown_menu_separator class="my-2" />
8484
<.dropdown_menu_item
8585
phx-click={@on_change}
8686
phx-value-value=""
8787
class="text-muted-foreground"
8888
>
89-
<.icon name="hero-x-mark" class="mr-2 h-4 w-4" /> Clear
89+
<span class="hero-x-circle mr-2 h-4 w-4" /> Clear selection
9090
</.dropdown_menu_item>
9191
<% end %>
9292
</.dropdown_menu_content>
9393
</.dropdown_menu>
94+
95+
<%= if @clearable && @selected do %>
96+
<button
97+
type="button"
98+
class="absolute right-2 h-4 w-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 flex items-center justify-center"
99+
phx-click={@on_change}
100+
phx-value-value=""
101+
>
102+
<span class="hero-x-mark h-4 w-4" />
103+
<span class="sr-only">Clear selection</span>
104+
</button>
105+
<% end %>
94106
</div>
95107
"""
96108
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule LiveFilter.MixProject do
22
use Mix.Project
33

4-
@version "0.1.6"
4+
@version "0.1.7"
55
@source_url "https://github.com/cpursley/livefilter"
66

77
def project do

0 commit comments

Comments
 (0)