Skip to content

Commit 9ca87d3

Browse files
authored
Set role=none in different place for ActionMenu form items (primer#2828)
1 parent 11aa0e9 commit 9ca87d3

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

.changeset/rotten-socks-appear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/view-components": patch
3+
---
4+
5+
Fix issue with ActionMenu form items which would prevent a wrapping form if form_arguments: was passed

app/components/primer/alpha/action_list/form_wrapper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def initialize(list:, action: nil, **form_arguments)
1919
@list = list
2020
@form_arguments = form_arguments
2121

22+
# When a form is inside a menu, suppress form semantics.
23+
# Otherwise, NVDA will miscount menu items.
24+
@form_arguments[:html] ||= {}
25+
@form_arguments[:html][:role] = :none
26+
2227
@action = action
2328
@http_method = extract_http_method(@form_arguments)
2429

app/components/primer/alpha/action_menu/list.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ def add_item(item, to:)
8989
def organize_arguments(data: {}, **system_arguments)
9090
content_arguments = system_arguments.delete(:content_arguments) || {}
9191

92-
# When a form is inside a menu, suppress form semantics.
93-
# Otherwise, NVDA will miscount menu items.
94-
form_arguments = system_arguments.delete(:form_arguments) || {}
95-
form_arguments[:html] = form_arguments[:html] || {}
96-
form_arguments[:html][:role] = :none
97-
9892
if system_arguments[:tag] && ITEM_TAG_OPTIONS.include?(system_arguments[:tag])
9993
content_arguments[:tag] = system_arguments[:tag]
10094
end
@@ -121,7 +115,7 @@ def organize_arguments(data: {}, **system_arguments)
121115
)
122116
end
123117

124-
{ data: data, **system_arguments, content_arguments: content_arguments, form_arguments: form_arguments }
118+
{ data: data, **system_arguments, content_arguments: content_arguments }
125119
end
126120
end
127121
end

test/components/alpha/action_menu_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ def test_does_not_double_render_show_button_content
189189

190190
assert @rendered_content.scan("test").size == 1, "The show button rendered its content more than once"
191191
end
192+
193+
def test_single_select_form_items_have_role_none
194+
render_preview(:single_select_form_items)
195+
196+
# one form per item
197+
assert_selector "form[role=none]", count: 2
198+
end
192199
end
193200
end
194201
end

0 commit comments

Comments
 (0)