Skip to content

Commit

Permalink
Update ActionMenu to forward overlay arguments (#2922)
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron authored Jun 25, 2024
1 parent 11b3b18 commit fb5917d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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

0 comments on commit fb5917d

Please sign in to comment.