Skip to content

Commit b9cce66

Browse files
authoredOct 14, 2024··
Allow form groups to accept system arguments (#3149)
1 parent 8587fc0 commit b9cce66

File tree

6 files changed

+33
-15
lines changed

6 files changed

+33
-15
lines changed
 

‎.changeset/hip-deers-rhyme.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/view-components': minor
3+
---
4+
5+
Allow form groups to accept system arguments

‎app/lib/primer/forms/base_component.rb

-8
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ def compile_and_render_template
6161
self.class.compile! unless self.class.instance_methods(false).include?(:render_template)
6262
render_template
6363
end
64-
65-
def content_tag_if(condition, tag, **kwargs, &block)
66-
if condition
67-
content_tag(tag, **kwargs, &block)
68-
else
69-
capture(&block)
70-
end
71-
end
7264
end
7365
end
7466
end

‎app/lib/primer/forms/group.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= content_tag_if(horizontal?, :div, class: "FormControl-horizontalGroup") do %>
1+
<%= render(Primer::Box.new(**@system_arguments)) do %>
22
<% @inputs.each do |input| %>
33
<%= render(input.to_component) %>
44
<% end %>

‎app/lib/primer/forms/group.rb

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ def initialize(inputs:, builder:, form:, layout: DEFAULT_LAYOUT, **system_argume
1717
@form = form
1818
@layout = layout
1919
@system_arguments = system_arguments
20+
21+
@system_arguments[:classes] = class_names(
22+
@system_arguments.delete(:classes),
23+
"FormControl-horizontalGroup" => horizontal?
24+
)
2025
end
2126

2227
def horizontal?
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
require "lib/test_helper"
4+
5+
class Primer::Forms::GroupInputTest < Minitest::Test
6+
include Primer::ComponentTestHelpers
7+
8+
def test_group_accepts_system_arguments
9+
render_in_view_context do
10+
primer_form_with(url: "/foo") do |f|
11+
render_inline_form(f) do |sys_args_form|
12+
sys_args_form.group(layout: :horizontal, border: true, p: 1) do |group|
13+
group.text_field(name: :first_name, label: "First name")
14+
group.text_field(name: :last_name, label: "Last name")
15+
end
16+
end
17+
end
18+
end
19+
20+
assert_selector ".FormControl-horizontalGroup.border.p-1"
21+
end
22+
end

‎test/lib/primer/forms_test.rb

-6
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,6 @@ def test_text_field_custom_element_is_form_control
297297
assert_selector "primer-text-field.FormControl"
298298
end
299299

300-
def test_siblings_are_form_controls_when_including_a_multi_input
301-
render_preview :multi_input_form
302-
303-
assert_selector ".FormControl-radio-group-wrap + .FormControl"
304-
end
305-
306300
def test_toggle_switch_button_labelled_by_label
307301
render_preview(:example_toggle_switch_form)
308302

0 commit comments

Comments
 (0)
Please sign in to comment.