diff --git a/.changeset/hip-deers-rhyme.md b/.changeset/hip-deers-rhyme.md new file mode 100644 index 0000000000..58401478a6 --- /dev/null +++ b/.changeset/hip-deers-rhyme.md @@ -0,0 +1,5 @@ +--- +'@primer/view-components': minor +--- + +Allow form groups to accept system arguments diff --git a/app/lib/primer/forms/base_component.rb b/app/lib/primer/forms/base_component.rb index 428f4f72d4..0199afc8b1 100644 --- a/app/lib/primer/forms/base_component.rb +++ b/app/lib/primer/forms/base_component.rb @@ -61,14 +61,6 @@ def compile_and_render_template self.class.compile! unless self.class.instance_methods(false).include?(:render_template) render_template end - - def content_tag_if(condition, tag, **kwargs, &block) - if condition - content_tag(tag, **kwargs, &block) - else - capture(&block) - end - end end end end diff --git a/app/lib/primer/forms/group.html.erb b/app/lib/primer/forms/group.html.erb index d918111edc..58058165ad 100644 --- a/app/lib/primer/forms/group.html.erb +++ b/app/lib/primer/forms/group.html.erb @@ -1,4 +1,4 @@ -<%= content_tag_if(horizontal?, :div, class: "FormControl-horizontalGroup") do %> +<%= render(Primer::Box.new(**@system_arguments)) do %> <% @inputs.each do |input| %> <%= render(input.to_component) %> <% end %> diff --git a/app/lib/primer/forms/group.rb b/app/lib/primer/forms/group.rb index 889603470b..2b7239b7f8 100644 --- a/app/lib/primer/forms/group.rb +++ b/app/lib/primer/forms/group.rb @@ -17,6 +17,11 @@ def initialize(inputs:, builder:, form:, layout: DEFAULT_LAYOUT, **system_argume @form = form @layout = layout @system_arguments = system_arguments + + @system_arguments[:classes] = class_names( + @system_arguments.delete(:classes), + "FormControl-horizontalGroup" => horizontal? + ) end def horizontal? diff --git a/test/lib/primer/forms/group_input_test.rb b/test/lib/primer/forms/group_input_test.rb new file mode 100644 index 0000000000..623aee11f5 --- /dev/null +++ b/test/lib/primer/forms/group_input_test.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require "lib/test_helper" + +class Primer::Forms::GroupInputTest < Minitest::Test + include Primer::ComponentTestHelpers + + def test_group_accepts_system_arguments + render_in_view_context do + primer_form_with(url: "/foo") do |f| + render_inline_form(f) do |sys_args_form| + sys_args_form.group(layout: :horizontal, border: true, p: 1) do |group| + group.text_field(name: :first_name, label: "First name") + group.text_field(name: :last_name, label: "Last name") + end + end + end + end + + assert_selector ".FormControl-horizontalGroup.border.p-1" + end +end diff --git a/test/lib/primer/forms_test.rb b/test/lib/primer/forms_test.rb index d6f7ef111b..d024523dad 100644 --- a/test/lib/primer/forms_test.rb +++ b/test/lib/primer/forms_test.rb @@ -297,12 +297,6 @@ def test_text_field_custom_element_is_form_control assert_selector "primer-text-field.FormControl" end - def test_siblings_are_form_controls_when_including_a_multi_input - render_preview :multi_input_form - - assert_selector ".FormControl-radio-group-wrap + .FormControl" - end - def test_toggle_switch_button_labelled_by_label render_preview(:example_toggle_switch_form)