File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ var React = require('react');
22var attributesToProps = require ( './attributes-to-props' ) ;
33var utilities = require ( './utilities' ) ;
44
5+ var setStyleProp = utilities . setStyleProp ;
6+
57/**
68 * Converts DOM nodes to React elements.
79 *
@@ -62,8 +64,10 @@ function domToReact(nodes, options) {
6264 }
6365
6466 props = node . attribs ;
65- if ( ! skipAttributesToProps ( node ) ) {
66- props = attributesToProps ( node . attribs ) ;
67+ if ( skipAttributesToProps ( node ) ) {
68+ setStyleProp ( props . style , props ) ;
69+ } else if ( props ) {
70+ props = attributesToProps ( props ) ;
6771 }
6872
6973 children = null ;
@@ -110,7 +114,7 @@ function domToReact(nodes, options) {
110114
111115/**
112116 * Determines whether DOM element attributes should be transformed to props.
113- * Web Components (custom elements) should not have their attributes transformed.
117+ * Web Components should not have their attributes transformed except for `style` .
114118 *
115119 * @param {DomElement } node
116120 * @return {boolean }
Original file line number Diff line number Diff line change @@ -19,7 +19,12 @@ exports[`domToReact converts custom element with attributes 1`] = `
1919<custom-element
2020 class = " myClass"
2121 custom-attribute = " value"
22- style = " -o-transition: all .5s; line-height: 1;"
22+ style = {
23+ Object {
24+ " OTransition" : " all .5s" ,
25+ " lineHeight" : " 1" ,
26+ }
27+ }
2328/>
2429`;
2530
@@ -87,6 +92,11 @@ exports[`domToReact when React >=16 preserves unknown attributes 1`] = `
8792<custom-element
8893 class = " myClass"
8994 custom-attribute = " value"
90- style = " -o-transition: all .5s; line-height: 1;"
95+ style = {
96+ Object {
97+ " OTransition" : " all .5s" ,
98+ " lineHeight" : " 1" ,
99+ }
100+ }
91101/>
92102`;
You can’t perform that action at this time.
0 commit comments