File tree 4 files changed +46
-3
lines changed
4 files changed +46
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @primer/view-components ' : patch
3
+ ---
4
+
5
+ Allow setting custom values on submit buttons.
Original file line number Diff line number Diff line change @@ -54,11 +54,14 @@ def input_arguments
54
54
private
55
55
56
56
def tag_attributes
57
+ attrs = { name : @input . name }
58
+ attrs [ :value ] = @input . value if @input . value
59
+
57
60
case @type
58
61
when :submit
59
- ButtonAttributeGenerator . submit_tag_attributes ( @input . label , name : @input . name )
62
+ ButtonAttributeGenerator . submit_tag_attributes ( @input . label , ** attrs )
60
63
else
61
- ButtonAttributeGenerator . button_tag_attributes ( @input . label , name : @input . name )
64
+ ButtonAttributeGenerator . button_tag_attributes ( @input . label , ** attrs )
62
65
end
63
66
end
64
67
end
Original file line number Diff line number Diff line change @@ -246,6 +246,10 @@ def id
246
246
@input_arguments [ :id ]
247
247
end
248
248
249
+ def value
250
+ @input_arguments [ :value ]
251
+ end
252
+
249
253
# :nocov:
250
254
def name
251
255
raise_for_abstract_method! ( __method__ )
@@ -305,7 +309,7 @@ def input_data
305
309
def caption_template_name
306
310
return nil unless name
307
311
308
- @caption_template_name ||= if respond_to? ( :value )
312
+ @caption_template_name ||= if respond_to? ( :value ) && value . present?
309
313
:"#{ name } _#{ value } "
310
314
else
311
315
name . to_sym
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "lib/test_helper"
4
+
5
+ class Primer ::Forms ::SubmitButtonInputTest < Minitest ::Test
6
+ include Primer ::ComponentTestHelpers
7
+
8
+ def test_uses_name_as_value_by_default
9
+ render_in_view_context do
10
+ primer_form_with ( url : "/foo" ) do |f |
11
+ render_inline_form ( f ) do |submit_button_form |
12
+ submit_button_form . submit ( name : :foo , label : "Foo" )
13
+ end
14
+ end
15
+ end
16
+
17
+ assert_selector "button[type=submit][value=Foo]"
18
+ end
19
+
20
+ def test_allows_overriding_value
21
+ render_in_view_context do
22
+ primer_form_with ( url : "/foo" ) do |f |
23
+ render_inline_form ( f ) do |submit_button_form |
24
+ submit_button_form . submit ( name : :foo , label : "Foo" , value : "bar" )
25
+ end
26
+ end
27
+ end
28
+
29
+ assert_selector "button[type=submit][value=bar]"
30
+ end
31
+ end
You can’t perform that action at this time.
0 commit comments