Skip to content

Commit

Permalink
Merge branch 'main' into dialog_disable_scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron authored Oct 14, 2024
2 parents 686ecf0 + 37e78c0 commit 0d7d733
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 258 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-games-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Allow setting custom values on submit buttons.
5 changes: 5 additions & 0 deletions .changeset/hip-deers-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': minor
---

Allow form groups to accept system arguments
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ app/components/**/*.css.json
app/components/**/*.css.map
app/components/**/*.d.ts
app/lib/primer/css/*.css.json
lib/primer/forms/**/*.js
lib/primer/forms/**/*.css
lib/primer/forms/**/*.css.json
lib/primer/forms/**/*.css.map
lib/primer/forms/**/*.d.ts
app/lib/primer/forms/**/*.js
app/lib/primer/forms/**/*.css
app/lib/primer/forms/**/*.css.json
app/lib/primer/forms/**/*.css.map
app/lib/primer/forms/**/*.d.ts
app/assets/

# Generated by demo npm post-install
Expand Down
File renamed without changes.
8 changes: 0 additions & 8 deletions app/lib/primer/forms/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions app/lib/primer/forms/button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ def input_arguments
private

def tag_attributes
attrs = { name: @input.name }
attrs[:value] = @input.value if @input.value

case @type
when :submit
ButtonAttributeGenerator.submit_tag_attributes(@input.label, name: @input.name)
ButtonAttributeGenerator.submit_tag_attributes(@input.label, **attrs)
else
ButtonAttributeGenerator.button_tag_attributes(@input.label, name: @input.name)
ButtonAttributeGenerator.button_tag_attributes(@input.label, **attrs)
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion app/lib/primer/forms/dsl/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ def id
@input_arguments[:id]
end

def value
@input_arguments[:value]
end

# :nocov:
def name
raise_for_abstract_method!(__method__)
Expand Down Expand Up @@ -305,7 +309,7 @@ def input_data
def caption_template_name
return nil unless name

@caption_template_name ||= if respond_to?(:value)
@caption_template_name ||= if respond_to?(:value) && value.present?
:"#{name}_#{value}"
else
name.to_sym
Expand Down
2 changes: 1 addition & 1 deletion app/lib/primer/forms/group.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>
Expand Down
5 changes: 5 additions & 0 deletions app/lib/primer/forms/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
10 changes: 0 additions & 10 deletions app/lib/primer/forms/primer_multi_input.d.ts

This file was deleted.

28 changes: 0 additions & 28 deletions app/lib/primer/forms/primer_text_field.d.ts

This file was deleted.

119 changes: 0 additions & 119 deletions app/lib/primer/forms/primer_text_field.js

This file was deleted.

5 changes: 0 additions & 5 deletions app/lib/primer/forms/toggle_switch_input.d.ts

This file was deleted.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
"app/components/primer/**/*.css.json",
"app/components/primer/**/*.d.ts",
"app/lib/primer/forms/**/*.js",
"app/lib/primer/forms/**/*.d.ts",
"lib/primer/forms/**/*.js",
"lib/primer/forms/**/*.d.ts"
"app/lib/primer/forms/**/*.d.ts"
],
"scripts": {
"clean": "git clean -fdX -- app/",
Expand Down
22 changes: 22 additions & 0 deletions test/lib/primer/forms/group_input_test.rb
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions test/lib/primer/forms/submit_button_input_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require "lib/test_helper"

class Primer::Forms::SubmitButtonInputTest < Minitest::Test
include Primer::ComponentTestHelpers

def test_uses_name_as_value_by_default
render_in_view_context do
primer_form_with(url: "/foo") do |f|
render_inline_form(f) do |submit_button_form|
submit_button_form.submit(name: :foo, label: "Foo")
end
end
end

assert_selector "button[type=submit][value=Foo]"
end

def test_allows_overriding_value
render_in_view_context do
primer_form_with(url: "/foo") do |f|
render_inline_form(f) do |submit_button_form|
submit_button_form.submit(name: :foo, label: "Foo", value: "bar")
end
end
end

assert_selector "button[type=submit][value=bar]"
end
end
6 changes: 0 additions & 6 deletions test/lib/primer/forms_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading

0 comments on commit 0d7d733

Please sign in to comment.