diff --git a/.changeset/forty-ways-grab.md b/.changeset/forty-ways-grab.md new file mode 100644 index 0000000000..a1daca9c62 --- /dev/null +++ b/.changeset/forty-ways-grab.md @@ -0,0 +1,5 @@ +--- +'@primer/view-components': minor +--- + +Change ActionMenu to accept and forward overlay arguments diff --git a/app/components/primer/alpha/action_menu.rb b/app/components/primer/alpha/action_menu.rb index 708989a7e7..c06e4c3ad5 100644 --- a/app/components/primer/alpha/action_menu.rb +++ b/app/components/primer/alpha/action_menu.rb @@ -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, @@ -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 @@ -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( diff --git a/test/components/alpha/action_menu_test.rb b/test/components/alpha/action_menu_test.rb index b22baf18e8..c96f580f52 100644 --- a/test/components/alpha/action_menu_test.rb +++ b/test/components/alpha/action_menu_test.rb @@ -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