Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label BorderBox lists with their header #2202

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions .changeset/lemon-bulldogs-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/view-components': patch
---

Label BorderBox lists with their header

<!-- Changed components: Primer::Beta::BorderBox -->
4 changes: 2 additions & 2 deletions app/components/primer/beta/border_box.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<%= header %>
<%= body %>
<% if rows.any? %>
<ul>
<%= render Primer::BaseComponent.new(**@list_arguments) do %>
<% rows.each do |row| %>
<%= row %>
<% end %>
</ul>
<% end %>
<% end %>
<%= footer %>
<% end %>
11 changes: 11 additions & 0 deletions app/components/primer/beta/border_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,22 @@ def initialize(padding: DEFAULT_PADDING, **system_arguments)
)

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

def render?
rows.any? || header.present? || body.present? || footer.present?
end

private

def before_render
return unless header

@list_arguments[:aria] = {
labelledby: header.id
}
end
end
end
end
4 changes: 4 additions & 0 deletions app/components/primer/beta/border_box/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class BorderBox
#
# @accessibility When using `header.with_title`, set `tag` to one of `h1`, `h2`, `h3`, etc. based on what is appropriate for the page context. <%= link_to_heading_practices %>
class Header < Primer::Component
attr_reader :id

status :beta

TITLE_TAG_FALLBACK = :h2
Expand All @@ -29,11 +31,13 @@ class Header < Primer::Component
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(**system_arguments)
@system_arguments = system_arguments
@system_arguments[:id] ||= self.class.generate_id
@system_arguments[:tag] = :div
@system_arguments[:classes] = class_names(
"Box-header",
system_arguments[:classes]
)
@id = @system_arguments[:id]
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/components/beta/border_box_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
assert_selector("div.Box-header", text: "Header")
end

def test_labels_list_with_header
render_inline(Primer::Beta::BorderBox.new) do |component|
component.with_header { "Header" }
component.with_row { "Row" }
end

id = page.find_css('.Box-header').first[:id]

Check failure on line 32 in test/components/beta/border_box_test.rb

View workflow job for this annotation

GitHub Actions / rubocop

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
assert_selector "ul[aria-labelledby='#{id}']"
end

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