Skip to content

Commit 1863522

Browse files
authored
Add parenthesis to trailing counter (primer#2807)
1 parent 2aae5e9 commit 1863522

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

.changeset/brown-boats-hunt.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+
Add parenthesis to trailing counter for React parity, and to improve screen reader speech output

app/components/primer/beta/button.html.erb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
<span class="Button-label"><%= trimmed_content %></span>
99
<% if trailing_visual %>
1010
<span class="Button-visual Button-trailingVisual">
11-
<%= trailing_visual %>
11+
<% if @trailing_visual_counter %>
12+
<span class="sr-only">(<%= trailing_visual %>)</span>
13+
<%= trailing_visual %>
14+
<% else %>
15+
<%= trailing_visual %>
16+
<% end %>
1217
</span>
1318
<% end %>
1419
</span>

app/components/primer/beta/button.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ class Button < Primer::Component
6868
renders_one :trailing_visual, types: {
6969
icon: Primer::Beta::Octicon,
7070
label: Primer::Beta::Label,
71-
counter: Primer::Beta::Counter
71+
counter: lambda { |**system_arguments|
72+
@trailing_visual_counter = true
73+
Primer::Beta::Counter.new("aria-hidden": true, **system_arguments)
74+
}
7275
}
7376

7477
# Trailing action appears to the right of the trailing visual.

test/components/primer/beta/button_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ def test_renders_with_leading_visual_icon
2727
assert_selector(".Button .Button-leadingVisual .octicon-alert")
2828
end
2929

30+
def test_renders_with_trailing_visual_counter
31+
render_inline(Primer::Beta::Button.new) do |component|
32+
component.with_trailing_visual_counter(count: 15)
33+
"Button"
34+
end
35+
36+
assert_selector(".Button", text: "Button")
37+
assert_selector('[aria-hidden="true"]', text: "15")
38+
# Parenthesis provides improved screen reader output
39+
assert_selector(".sr-only", text: "(15)")
40+
end
41+
3042
def test_renders_with_leading_visual_svg
3143
render_inline(Primer::Beta::Button.new) do |component|
3244
component.with_leading_visual_svg do

0 commit comments

Comments
 (0)