Skip to content

Commit 82b8850

Browse files
committed
Allow to pass strategy option to dropdown menu
1 parent eea116e commit 82b8850

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

lib/ruby_ui/dropdown_menu/dropdown_menu.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ def view_template(&)
1515

1616
def default_attrs
1717
{
18+
class: [
19+
'group/dropdown-menu',
20+
@strategy == 'absolute' ? 'is-absolute' : 'is-fixed'
21+
],
1822
data: {
19-
controller: "ruby-ui--dropdown-menu",
20-
action: "click@window->ruby-ui--dropdown-menu#onClickOutside",
23+
controller: 'ruby-ui--dropdown-menu',
24+
action: 'click@window->ruby-ui--dropdown-menu#onClickOutside',
2125
ruby_ui__dropdown_menu_options_value: @options.to_json
2226
}
2327
}

lib/ruby_ui/dropdown_menu/dropdown_menu_content.rb

+17-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module RubyUI
44
class DropdownMenuContent < Base
55
def view_template(&block)
6-
div(data: {ruby_ui__dropdown_menu_target: "content"}, class: "hidden", style: "width: max-content; position: absolute; top: 0; left: 0;") do
6+
div(**wrapper_attrs) do
77
div(**attrs, &block)
88
end
99
end
@@ -15,7 +15,22 @@ def default_attrs
1515
data: {
1616
state: :open
1717
},
18-
class: "z-50 min-w-[8rem] overflow-hidden rounded-md border bg-background p-1 text-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 w-56"
18+
class: 'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-background p-1 text-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 w-56'
19+
}
20+
end
21+
22+
def wrapper_attrs
23+
{
24+
class: [
25+
'z-50 hidden group-[.is-absolute]/dropdown-menu:absolute',
26+
'group-[.is-fixed]/dropdown-menu:fixed'
27+
],
28+
data: { ruby_ui__dropdown_menu_target: 'content' },
29+
style: {
30+
width: 'max-content',
31+
top: '0',
32+
left: '0'
33+
}
1934
}
2035
end
2136
end

0 commit comments

Comments
 (0)