diff --git a/.changeset/rotten-socks-appear.md b/.changeset/rotten-socks-appear.md new file mode 100644 index 0000000000..f8a7cf7992 --- /dev/null +++ b/.changeset/rotten-socks-appear.md @@ -0,0 +1,5 @@ +--- +"@primer/view-components": patch +--- + +Fix issue with ActionMenu form items which would prevent a wrapping form if form_arguments: was passed diff --git a/app/components/primer/alpha/action_list/form_wrapper.rb b/app/components/primer/alpha/action_list/form_wrapper.rb index b44e98f5c8..2a431ba8f4 100644 --- a/app/components/primer/alpha/action_list/form_wrapper.rb +++ b/app/components/primer/alpha/action_list/form_wrapper.rb @@ -19,6 +19,11 @@ def initialize(list:, action: nil, **form_arguments) @list = list @form_arguments = form_arguments + # When a form is inside a menu, suppress form semantics. + # Otherwise, NVDA will miscount menu items. + @form_arguments[:html] ||= {} + @form_arguments[:html][:role] = :none + @action = action @http_method = extract_http_method(@form_arguments) diff --git a/app/components/primer/alpha/action_menu/list.rb b/app/components/primer/alpha/action_menu/list.rb index c439fe0e8d..0749a815e6 100644 --- a/app/components/primer/alpha/action_menu/list.rb +++ b/app/components/primer/alpha/action_menu/list.rb @@ -89,12 +89,6 @@ def add_item(item, to:) def organize_arguments(data: {}, **system_arguments) content_arguments = system_arguments.delete(:content_arguments) || {} - # When a form is inside a menu, suppress form semantics. - # Otherwise, NVDA will miscount menu items. - form_arguments = system_arguments.delete(:form_arguments) || {} - form_arguments[:html] = form_arguments[:html] || {} - form_arguments[:html][:role] = :none - if system_arguments[:tag] && ITEM_TAG_OPTIONS.include?(system_arguments[:tag]) content_arguments[:tag] = system_arguments[:tag] end @@ -121,7 +115,7 @@ def organize_arguments(data: {}, **system_arguments) ) end - { data: data, **system_arguments, content_arguments: content_arguments, form_arguments: form_arguments } + { data: data, **system_arguments, content_arguments: content_arguments } end end end diff --git a/test/components/alpha/action_menu_test.rb b/test/components/alpha/action_menu_test.rb index 8e0bd2a76a..b22baf18e8 100644 --- a/test/components/alpha/action_menu_test.rb +++ b/test/components/alpha/action_menu_test.rb @@ -189,6 +189,13 @@ def test_does_not_double_render_show_button_content assert @rendered_content.scan("test").size == 1, "The show button rendered its content more than once" end + + def test_single_select_form_items_have_role_none + render_preview(:single_select_form_items) + + # one form per item + assert_selector "form[role=none]", count: 2 + end end end end