Skip to content

Commit 2c8fdc6

Browse files
authored
Add footer slot to DropdownComponent (#4682)
1 parent 357770d commit 2c8fdc6

5 files changed

Lines changed: 63 additions & 0 deletions

File tree

app/assets/stylesheets/css/components/ui/dropdown.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,34 @@
160160
outline-offset: var(--focus-outline-offset-inset);
161161
}
162162

163+
/* ==========================================================================
164+
Footer (DropdownComponent with_footer)
165+
A row under the list, outside the scrollable group and the inline search's
166+
filter scope — always visible. Items share the menu-item metrics but read
167+
quieter, as footer actions rather than options.
168+
========================================================================== */
169+
170+
.dropdown-menu__footer {
171+
@apply flex flex-col self-stretch p-1 border-t border-tertiary;
172+
}
173+
174+
.dropdown-menu__footer :is(a, button) {
175+
@apply flex items-center w-full justify-start gap-1.5 px-2 py-1.5 min-h-8 rounded-md border-none bg-transparent whitespace-nowrap text-content-secondary font-normal text-sm cursor-pointer leading-5;
176+
177+
&:hover {
178+
@apply bg-secondary text-content;
179+
}
180+
181+
&:focus-visible {
182+
@apply bg-primary;
183+
outline-offset: var(--focus-outline-offset-inset);
184+
}
185+
186+
svg {
187+
@apply shrink-0 size-4 text-inherit;
188+
}
189+
}
190+
163191
.dropdown-menu__icon,
164192
.dropdown-menu__list > :is(a, button) svg {
165193
@apply shrink-0 size-4 text-inherit;

app/components/avo/u_i/dropdown_component.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
<% if @searchable %>
3030
<p class="dropdown-menu__search-empty" data-popover-menu-target="empty" hidden>No matching options</p>
3131
<% end %>
32+
<% if footer? %>
33+
<div class="dropdown-menu__footer"><%= footer %></div>
34+
<% end %>
3235
</div>
3336
<% end %>
3437
<% end %>

app/components/avo/u_i/dropdown_component.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class Avo::UI::DropdownComponent < Avo::BaseComponent
1414

1515
renders_one :trigger
1616
renders_one :items
17+
# A row pinned under the list — outside the scrollable group and the inline
18+
# search's filter scope, so it stays visible. Popover mode only.
19+
renders_one :footer
1720

1821
# this is used to trigger the dropdown menu from trigger element
1922
# data: {action: component.action} => click->dropdown-menu#toggle

spec/dummy/test/components/previews/u_i/dropdown_component_preview.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def default
4242
def searchable
4343
render_with_template(template: "u_i/dropdown_component_preview/searchable")
4444
end
45+
46+
# Popover dropdown with a footer row pinned under the (filterable) list
47+
def with_footer
48+
render_with_template(template: "u_i/dropdown_component_preview/with_footer")
49+
end
4550
# @!endgroup
4651
end
4752
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<div class="border-2 border-gray-200 rounded-md p-4 w-96 flex justify-center items-center">
2+
<%= render Avo::UI::DropdownComponent.new(popover_mode: true, searchable: true) do |component| %>
3+
<% component.with_trigger do %>
4+
<button type="button"
5+
class="inline-flex items-center justify-center rounded-md p-1 cursor-pointer"
6+
popovertarget="<%= component.popover_id %>"
7+
aria-haspopup="menu"
8+
aria-label="Fruits">
9+
<%= svg "tabler/outline/dots-vertical" %>
10+
</button>
11+
<% end %>
12+
<% component.with_items do %>
13+
<% %w[Apple Avocado Banana Cherry Mango Peach Pear Plum].each do |fruit| %>
14+
<%= button_tag(fruit, type: "button") %>
15+
<% end %>
16+
<% end %>
17+
<% component.with_footer do %>
18+
<%= link_to "#" do %>
19+
<%= svg "tabler/outline/external-link" %>
20+
All fruits
21+
<% end %>
22+
<% end %>
23+
<% end %>
24+
</div>

0 commit comments

Comments
 (0)