This repository was archived by the owner on Oct 19, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,8 @@ def self.convert_props(properties)
108
108
props [ "className" ] = value
109
109
elsif [ "style" , "dangerously_set_inner_HTML" ] . include? key
110
110
props [ lower_camelize ( key ) ] = value . to_n
111
+ elsif React ::HASH_ATTRIBUTES . include? ( key ) && value . is_a? ( Hash )
112
+ value . each { |k , v | props [ "#{ key } -#{ k . tr ( '_' , '-' ) } " ] = v . to_n }
111
113
else
112
114
props [ React . html_attr? ( lower_camelize ( key ) ) ? lower_camelize ( key ) : key ] = value
113
115
end
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ module React
34
34
strokeOpacity strokeWidth textAnchor transform version
35
35
viewBox x1 x2 x xlinkActuate xlinkArcrole xlinkHref xlinkRole
36
36
xlinkShow xlinkTitle xlinkType xmlBase xmlLang xmlSpace y1 y2 y )
37
+ HASH_ATTRIBUTES = %w( data aria )
38
+
37
39
38
40
def self . html_tag? ( name )
39
41
tags = HTML_TAGS
Original file line number Diff line number Diff line change @@ -136,6 +136,32 @@ def render
136
136
expect ( React . render_to_static_markup ( React . create_element ( Foo ) ) ) . to eq ( '<div>Hello Goodby</div>' )
137
137
end
138
138
139
+ it 'should convert a hash param to hyphenated html attributes if in React::HASH_ATTRIBUTES' do
140
+ stub_const 'Foo' , Class . new
141
+ Foo . class_eval do
142
+ include React ::Component
143
+ def render
144
+ div ( data : { foo : :bar } , aria : { foo_bar : :foo } )
145
+ end
146
+ end
147
+
148
+ expect ( React . render_to_static_markup ( React . create_element ( Foo ) ) )
149
+ . to eq ( '<div data-foo="bar" aria-foo-bar="foo"></div>' )
150
+ end
151
+
152
+ it 'should not convert a hash param to hyphenated html attributes if not in React::HASH_ATTRIBUTES' do
153
+ stub_const 'Foo' , Class . new
154
+ Foo . class_eval do
155
+ include React ::Component
156
+ def render
157
+ div ( title : { bar : :foo } )
158
+ end
159
+ end
160
+
161
+ expect ( React . render_to_static_markup ( React . create_element ( Foo ) ) )
162
+ . to eq ( '<div title="{"bar"=>"foo"}"></div>' )
163
+ end
164
+
139
165
it "will remove all elements passed as params from the rendering buffer" do
140
166
stub_const 'X2' , Class . new
141
167
X2 . class_eval do
You can’t perform that action at this time.
0 commit comments