diff --git a/package.json b/package.json
index 5894ce55..9236f183 100644
--- a/package.json
+++ b/package.json
@@ -31,9 +31,10 @@
},
"dependencies": {
"deep-equal": "^1.0.1",
+ "lodash.kebabcase": "^4.1.1",
"object-assign": "^4.1.1",
- "react-side-effect": "^1.1.0",
- "prop-types": "^15.5.4"
+ "prop-types": "^15.5.4",
+ "react-side-effect": "^1.1.0"
},
"devDependencies": {
"babel-cli": "^6.24.0",
diff --git a/src/Helmet.js b/src/Helmet.js
index d88ee7e4..bbf339b4 100644
--- a/src/Helmet.js
+++ b/src/Helmet.js
@@ -7,7 +7,8 @@ import {
handleClientStateChange,
mapStateOnServer,
reducePropsToState,
- warn
+ warn,
+ getBodyStyleAttributeValue
} from "./HelmetUtils.js";
import {TAG_NAMES, VALID_TAG_NAMES} from "./HelmetConstants.js";
@@ -149,9 +150,16 @@ const Helmet = Component =>
};
case TAG_NAMES.BODY:
+ if (newChildProps.style) {
+ newChildProps.style = getBodyStyleAttributeValue(
+ newChildProps.style
+ );
+ }
return {
...newProps,
- bodyAttributes: {...newChildProps}
+ bodyAttributes: {
+ ...newChildProps
+ }
};
case TAG_NAMES.HTML:
diff --git a/src/HelmetUtils.js b/src/HelmetUtils.js
index 63ad85a6..37a84522 100644
--- a/src/HelmetUtils.js
+++ b/src/HelmetUtils.js
@@ -1,5 +1,7 @@
import React from "react";
import objectAssign from "object-assign";
+import kebabCase from "lodash.kebabcase";
+
import {
ATTRIBUTE_NAMES,
HELMET_ATTRIBUTE,
@@ -640,9 +642,19 @@ const mapStateOnServer = ({
title: getMethodsForTag(TAG_NAMES.TITLE, {title, titleAttributes}, encode)
});
+const getBodyStyleAttributeValue = (style: ?any) => {
+ if (typeof style === "object") {
+ return Object.keys(style)
+ .map(key => `${kebabCase(key)}: ${style[key]}`)
+ .join(";");
+ }
+ return style;
+};
+
export {convertReactPropstoHtmlAttributes};
export {handleClientStateChange};
export {mapStateOnServer};
export {reducePropsToState};
export {requestAnimationFrame};
export {warn};
+export {getBodyStyleAttributeValue};
diff --git a/test/HelmetDeclarativeTest.js b/test/HelmetDeclarativeTest.js
index bdcf5229..a3aa39d2 100644
--- a/test/HelmetDeclarativeTest.js
+++ b/test/HelmetDeclarativeTest.js
@@ -774,6 +774,47 @@ describe("Helmet - Declarative API", () => {
});
});
+ it("body style attribute as string", done => {
+ ReactDOM.render(
+