Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/forty-ways-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': minor
---

Change ActionMenu to accept and forward overlay arguments
5 changes: 4 additions & 1 deletion app/components/primer/alpha/action_menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class ActionMenu < Primer::Component
# @param dynamic_label_prefix [String] If provided, the prefix is prepended to the dynamic label and displayed in the show button.
# @param select_variant [Symbol] <%= one_of(Primer::Alpha::ActionMenu::SELECT_VARIANT_OPTIONS) %>
# @param form_arguments [Hash] Allows an `ActionMenu` to act as a select list in multi- and single-select modes. Pass the `builder:` and `name:` options to this hash. `builder:` should be an instance of `ActionView::Helpers::FormBuilder`, which are created by the standard Rails `#form_with` and `#form_for` helpers. The `name:` option is the desired name of the field that will be included in the params sent to the server on form submission.
# @param overlay_arguments [Hash] Arguments to pass to the underlying %= link_to_component(Primer::Alpha::Overlay) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>.
def initialize(
menu_id: self.class.generate_id,
Expand All @@ -199,6 +200,7 @@ def initialize(
dynamic_label_prefix: nil,
select_variant: DEFAULT_SELECT_VARIANT,
form_arguments: {},
overlay_arguments: {},
**system_arguments
)
@menu_id = menu_id
Expand All @@ -221,7 +223,8 @@ def initialize(
visually_hide_title: true,
anchor_align: anchor_align,
anchor_side: anchor_side,
size: size
size: size,
**overlay_arguments
)

@list = Primer::Alpha::ActionMenu::List.new(
Expand Down
8 changes: 8 additions & 0 deletions test/components/alpha/action_menu_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ def test_single_select_form_items_have_role_none
# one form per item
assert_selector "form[role=none]", count: 2
end

def test_forwards_overlay_arguments
render_inline(Primer::Alpha::ActionMenu.new(menu_id: "foo", overlay_arguments: { data: { foo: "bar" } })) do |menu|
menu.with_item { "foo" }
end

assert_selector "anchored-position[data-foo=bar]"
end
end
end
end