Skip to content

Commit b0fc06c

Browse files
committed
Teach BorderBox component a list_arguments param
Allows additional customization of the rendered `<ul>` by supporting system arguments. Closes primer#3820
1 parent 3e667a3 commit b0fc06c

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

app/components/primer/beta/border_box.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ class BorderBox < Primer::Component
7171
}
7272

7373
# @param padding [Symbol] <%= one_of(Primer::Beta::BorderBox::PADDING_MAPPINGS.keys) %>
74+
# @param list_arguments [Hash] <%= link_to_system_arguments_docs %>
7475
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
75-
def initialize(padding: DEFAULT_PADDING, **system_arguments)
76+
def initialize(padding: DEFAULT_PADDING, list_arguments: {}, **system_arguments)
7677
list_id = system_arguments.delete(:list_id)
7778

7879
@system_arguments = deny_tag_argument(**system_arguments)
@@ -84,9 +85,10 @@ def initialize(padding: DEFAULT_PADDING, **system_arguments)
8485
)
8586

8687
@system_arguments[:system_arguments_denylist] = { [:p, :pt, :pb, :pr, :pl] => PADDING_SUGGESTION }
87-
@list_arguments = { tag: :ul }
88+
@list_arguments = deny_tag_argument(**list_arguments)
89+
@list_arguments[:tag] = :ul
8890
@list_arguments[:id] = list_id if list_id
89-
@list_arguments[:classes] = "Box-list"
91+
@list_arguments[:classes] = class_names("Box-list", @list_arguments[:classes])
9092
end
9193

9294
def render?
@@ -98,9 +100,10 @@ def render?
98100
def before_render
99101
return unless header
100102

101-
@list_arguments[:aria] = {
102-
labelledby: header.id
103-
}
103+
@list_arguments[:aria] = merge_aria(
104+
@list_arguments,
105+
{ aria: { labelledby: header.id } }
106+
)
104107
end
105108
end
106109
end

test/components/beta/border_box_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ def test_labels_list_with_header
3333
assert_selector "ul[aria-labelledby='#{id}']"
3434
end
3535

36+
def test_renders_list_with_list_arguments
37+
render_inline(Primer::Beta::BorderBox.new(list_arguments: { id: "fake-tbody", role: "rowgroup" })) do |component|
38+
component.with_row { "Row" }
39+
end
40+
41+
assert_selector "ul#fake-tbody"
42+
assert_selector 'ul[role="rowgroup"]'
43+
end
44+
45+
def test_labels_list_with_header_and_additional_label
46+
render_inline(Primer::Beta::BorderBox.new(list_arguments: { aria: { labelledby: "my-footer" } })) do |component|
47+
component.with_header { "Header" }
48+
component.with_row { "Row" }
49+
component.with_footer(id: "my-footer") { "Footer" }
50+
end
51+
52+
header_id = page.find_css(".Box-header").first[:id]
53+
footer_id = page.find_css(".Box-footer").first[:id]
54+
assert_selector "ul[aria-labelledby*='#{header_id}']"
55+
assert_selector "ul[aria-labelledby*='#{footer_id}']"
56+
end
57+
3658
def test_renders_body
3759
render_inline(Primer::Beta::BorderBox.new) do |component|
3860
component.with_body { "Body" }

0 commit comments

Comments
 (0)