Skip to content

Commit

Permalink
Set role=none in different place for ActionMenu form items (#2828)
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron committed May 8, 2024
1 parent 11aa0e9 commit 9ca87d3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-socks-appear.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions app/components/primer/alpha/action_list/form_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 1 addition & 7 deletions app/components/primer/alpha/action_menu/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/components/alpha/action_menu_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9ca87d3

Please sign in to comment.