Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rare-coats-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Teach BorderBox component a list_arguments param
13 changes: 8 additions & 5 deletions app/components/primer/beta/border_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ class BorderBox < Primer::Component
}

# @param padding [Symbol] <%= one_of(Primer::Beta::BorderBox::PADDING_MAPPINGS.keys) %>
# @param list_arguments [Hash] <%= link_to_system_arguments_docs %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(padding: DEFAULT_PADDING, **system_arguments)
def initialize(padding: DEFAULT_PADDING, list_arguments: {}, **system_arguments)
@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:tag] = :div
@system_arguments[:classes] = class_names(
Expand All @@ -82,7 +83,8 @@ def initialize(padding: DEFAULT_PADDING, **system_arguments)
)

@system_arguments[:system_arguments_denylist] = { [:p, :pt, :pb, :pr, :pl] => PADDING_SUGGESTION }
@list_arguments = { tag: :ul }
@list_arguments = deny_tag_argument(**list_arguments)
@list_arguments[:tag] = :ul
end

def render?
Expand All @@ -94,9 +96,10 @@ def render?
def before_render
return unless header

@list_arguments[:aria] = {
labelledby: header.id
}
@list_arguments[:aria] = merge_aria(
@list_arguments,
{ aria: { labelledby: header.id } }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also explicitly disallow aria-label. However, this is probably being overly-defensive and I don't think it's being done elsewhere.

)
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions previews/primer/beta/border_box_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ module Beta
class BorderBoxPreview < ViewComponent::Preview
# @label Playground
#
# @param list_id text
# @param padding [Symbol] select [default, condensed, spacious]
# @param scheme [Symbol] select [default, neutral, info, warning]
def playground(padding: :default, scheme: :default)
render(Primer::Beta::BorderBox.new(padding: padding)) do |component|
def playground(padding: :default, scheme: :default, list_id: "my-list")
render(Primer::Beta::BorderBox.new(padding: padding, list_arguments: { id: list_id })) do |component|
component.with_header { "Header" }
component.with_body { "Body" }
component.with_row(scheme: scheme) { "#{scheme.to_s.capitalize} row one" }
Expand Down
22 changes: 22 additions & 0 deletions test/components/beta/border_box_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ def test_labels_list_with_header
assert_selector "ul[aria-labelledby='#{id}']"
end

def test_renders_list_with_list_arguments
render_inline(Primer::Beta::BorderBox.new(list_arguments: { id: "fake-tbody", role: "rowgroup" })) do |component|
component.with_row { "Row" }
end

assert_selector "ul#fake-tbody"
assert_selector 'ul[role="rowgroup"]'
end

def test_labels_list_with_header_and_additional_label
render_inline(Primer::Beta::BorderBox.new(list_arguments: { aria: { labelledby: "my-footer" } })) do |component|
component.with_header { "Header" }
component.with_row { "Row" }
component.with_footer(id: "my-footer") { "Footer" }
end

header_id = page.find_css(".Box-header").first[:id]
footer_id = page.find_css(".Box-footer").first[:id]
assert_selector "ul[aria-labelledby*='#{header_id}']"
assert_selector "ul[aria-labelledby*='#{footer_id}']"
end

def test_renders_body
render_inline(Primer::Beta::BorderBox.new) do |component|
component.with_body { "Body" }
Expand Down