Skip to content

Commit c2b88cb

Browse files
authored
Add a new custom label for close button in dialog header (#3447)
1 parent 8924e20 commit c2b88cb

File tree

7 files changed

+70
-1
lines changed

7 files changed

+70
-1
lines changed

.changeset/hip-cherries-glow.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 a new custom label for close button in dialog header

app/components/primer/alpha/dialog/header.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<% end %>
1414
</div>
1515
<div class="Overlay-actionWrap">
16-
<%= render Primer::Beta::CloseButton.new(classes: "Overlay-closeButton", "data-close-dialog-id": @id) %>
16+
<%= render Primer::Beta::CloseButton.new(classes: "Overlay-closeButton", "data-close-dialog-id": @id, aria: { label: @close_label }) %>
1717
</div>
1818
</div>
1919
<%= filter %>

app/components/primer/alpha/dialog/header.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class Header < Primer::Component
1616
}.freeze
1717
VARIANT_OPTIONS = VARIANT_MAPPINGS.keys
1818

19+
DEFAULT_CLOSE_LABEL = "Close"
20+
1921
# Optional filter slot for adding a filter input to the header.
2022
#
2123
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
@@ -48,6 +50,7 @@ class Header < Primer::Component
4850
# @param show_divider [Boolean] Show a divider between the header and body.
4951
# @param visually_hide_title [Boolean] Visually hide the `title` while maintaining a label for assistive technologies.
5052
# @param variant [Symbol] <%= one_of(Primer::Alpha::Dialog::Header::VARIANT_OPTIONS) %>
53+
# @param close_label [String] The aria-label text of the close "x" button.
5154
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
5255
def initialize(
5356
id:,
@@ -56,12 +59,14 @@ def initialize(
5659
show_divider: false,
5760
visually_hide_title: false,
5861
variant: DEFAULT_VARIANT,
62+
close_label: DEFAULT_CLOSE_LABEL,
5963
**system_arguments
6064
)
6165
@id = id
6266
@title = title
6367
@subtitle = subtitle
6468
@visually_hide_title = visually_hide_title
69+
@close_label = close_label
6570
@system_arguments = deny_tag_argument(**system_arguments)
6671
@system_arguments[:tag] = :div
6772

previews/primer/alpha/dialog_preview.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,38 @@ def initally_open(title: "Test Dialog", subtitle: nil, size: :medium, button_tex
302302
def with_header_filter
303303
render_with_template(locals: {})
304304
end
305+
306+
# @label With custom label for close button of header
307+
#
308+
# @param title [String] text
309+
# @param subtitle [String] text
310+
# @param button_text [String] text
311+
# @param show_divider [Boolean] toggle
312+
# @param close_label [String] text
313+
def with_header_close_button_label(title: "Test Dialog", subtitle: nil, button_text: "Show Dialog", show_divider: true, close_label: "Close me!")
314+
render_with_template(locals: {
315+
title: title,
316+
subtitle: subtitle,
317+
button_text: button_text,
318+
show_divider: show_divider,
319+
close_label: close_label
320+
})
321+
end
322+
323+
# @label Without custom label for close button of header
324+
#
325+
# @param title [String] text
326+
# @param subtitle [String] text
327+
# @param button_text [String] text
328+
# @param show_divider [Boolean] toggle
329+
def without_header_close_button_label(title: "Test Dialog", subtitle: nil, button_text: "Show Dialog", show_divider: true)
330+
render_with_template(locals: {
331+
title: title,
332+
subtitle: subtitle,
333+
button_text: button_text,
334+
show_divider: show_divider
335+
})
336+
end
305337
end
306338
end
307339
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<%= render(Primer::Alpha::Dialog.new(id: "my-dialog", title: title, subtitle: subtitle, visually_hide_title: false)) do |dialog| %>
2+
<% dialog.with_header(show_divider: show_divider, close_label: close_label) %>
3+
<% dialog.with_show_button_content(button_text) %>
4+
<% dialog.with_body_content("Hello World") %>
5+
<% end %>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<%= render(Primer::Alpha::Dialog.new(id: "my-dialog", title: title, subtitle: subtitle, visually_hide_title: false)) do |dialog| %>
2+
<% dialog.with_header(show_divider: show_divider, close_scheme: :none) %>
3+
<% dialog.with_show_button_content(button_text) %>
4+
<% dialog.with_body_content("Hello World") %>
5+
<% dialog.with_footer do %>
6+
<%= render(Primer::Beta::Button.new(data: { "close-dialog-id": "my-dialog" })) { "Close" } %>
7+
<% end %>
8+
<% end %>

test/components/primer/alpha/dialog_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,20 @@ def test_renders_footer_with_divider_if_show_divider_is_true
129129
assert_selector(".Overlay-footer.Overlay-footer--divided")
130130
end
131131
end
132+
133+
def test_renders_header_with_close_label
134+
render_inline(Primer::Alpha::Dialog.new(title: "Title", id: "my-dialog")) do |component|
135+
component.with_body { "content" }
136+
component.with_header(close_label: "Close me!") { "header" }
137+
end
138+
139+
assert_selector("dialog") do
140+
assert_selector(".Overlay-header") do
141+
assert_selector(".Overlay-actionWrap")
142+
assert_selector("button[data-close-dialog-id][aria-label='Close me!']")
143+
end
144+
end
145+
end
132146
end
133147
end
134148
end

0 commit comments

Comments
 (0)