Skip to content

Commit 10e6096

Browse files
committed
Add Dialog::Header close_scheme, close_label params
Allows the customization of the close button - or removal entirely.
1 parent d569987 commit 10e6096

File tree

6 files changed

+98
-3
lines changed

6 files changed

+98
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@
1212
<%= subtitle %>
1313
<% end %>
1414
</div>
15-
<div class="Overlay-actionWrap">
16-
<%= render Primer::Beta::CloseButton.new(classes: "Overlay-closeButton", "data-close-dialog-id": @id) %>
17-
</div>
15+
<% if @close_scheme != :none %>
16+
<div class="Overlay-actionWrap">
17+
<%= render(
18+
Primer::Beta::CloseButton.new(
19+
classes: "Overlay-closeButton",
20+
aria: { label: @close_label },
21+
data: { close_dialog_id: @id }
22+
)
23+
) %>
24+
</div>
25+
<% end %>
1826
</div>
1927
<%= filter %>
2028
<% end %>

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

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

19+
DEFAULT_CLOSE_SCHEME = :close
20+
CLOSE_SCHEMES = [
21+
DEFAULT_CLOSE_SCHEME,
22+
:none
23+
].freeze
24+
25+
DEFAULT_CLOSE_LABEL = "Close"
26+
1927
# Optional filter slot for adding a filter input to the header.
2028
#
2129
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
@@ -48,6 +56,8 @@ class Header < Primer::Component
4856
# @param show_divider [Boolean] Show a divider between the header and body.
4957
# @param visually_hide_title [Boolean] Visually hide the `title` while maintaining a label for assistive technologies.
5058
# @param variant [Symbol] <%= one_of(Primer::Alpha::Dialog::Header::VARIANT_OPTIONS) %>
59+
# @param close_scheme [Symbol] Whether the component can be closed with an "x" button. <%= one_of(Primer::Alpha::Banner::CLOSE_SCHEMES) %>
60+
# @param close_label [String] The aria-label text of the close "x" button.
5161
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
5262
def initialize(
5363
id:,
@@ -56,12 +66,16 @@ def initialize(
5666
show_divider: false,
5767
visually_hide_title: false,
5868
variant: DEFAULT_VARIANT,
69+
close_scheme: DEFAULT_CLOSE_SCHEME,
70+
close_label: DEFAULT_CLOSE_LABEL,
5971
**system_arguments
6072
)
6173
@id = id
6274
@title = title
6375
@subtitle = subtitle
6476
@visually_hide_title = visually_hide_title
77+
@close_scheme = close_scheme
78+
@close_label = close_label
6579
@system_arguments = deny_tag_argument(**system_arguments)
6680
@system_arguments[:tag] = :div
6781

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 Header Close Button label
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 Header Close Button
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(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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,34 @@ def test_renders_header_subtitle
9898
assert_selector(".Overlay-header .Overlay-description")
9999
end
100100

101+
def test_renders_header_with_close_label
102+
render_inline(Primer::Alpha::Dialog.new(title: "Title", id: "my-dialog")) do |component|
103+
component.with_body { "content" }
104+
component.with_header(close_label: "Close me!") { "header" }
105+
end
106+
107+
assert_selector("dialog") do
108+
assert_selector(".Overlay-header") do
109+
assert_selector(".Overlay-actionWrap")
110+
assert_selector("button[data-close-dialog-id][aria-label='Close me!']")
111+
end
112+
end
113+
end
114+
115+
def test_renders_header_with_close_scheme_none
116+
render_inline(Primer::Alpha::Dialog.new(title: "Title", id: "my-dialog")) do |component|
117+
component.with_body { "content" }
118+
component.with_header(close_scheme: :none) { "header" }
119+
end
120+
121+
assert_selector("dialog") do
122+
assert_selector(".Overlay-header") do
123+
refute_selector(".Overlay-actionWrap")
124+
refute_selector("button[data-close-dialog-id]")
125+
end
126+
end
127+
end
128+
101129
def test_renders_header_with_filter
102130
render_preview(:with_header_filter)
103131

0 commit comments

Comments
 (0)