Skip to content

Commit

Permalink
Add support for html attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierelopez committed Oct 25, 2015
1 parent ae95de9 commit 434dcc0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ General Use Props:
| `scripts` | array | A list of scripts in one of three forms: string paths `'mysite.com/script.js'`, script src objects `{ src: 'mysite.com/script.js' }` or inline scripts `{ inline: 'var x = 1;' }` | `[ ]`
| `stylesheets` | array | A list of stylesheet in one of three forms: string paths `'mysite.com/styles.css'`, style href objects `{ href: 'mysite.com/styles.css' }` or inline styles `{ inline: 'body { color: '#333' }' }` | `[ ]`
| `childrenContainerId` | string | The id for the dom element that contains the children nodes. | `'app'`
| `htmlAttributes` | object | [Attributes](https://facebook.github.io/react/docs/tags-and-attributes.html#supported-attributes) that you'd like to use on the html tag. | `{ }`

Props for Universal Rendering:

Expand Down
4 changes: 3 additions & 1 deletion src/HTMLDocument.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class HTMLDocument extends Component {

render() {
return (
<html>
<html {...this.props.htmlAttributes}>
<head>
<title>{this.props.title}</title>
{this.renderMetatags()}
Expand All @@ -112,6 +112,7 @@ class HTMLDocument extends Component {
HTMLDocument.propTypes = {
childrenContainerId: PropTypes.string,
children: PropTypes.node,
htmlAttributes: PropTypes.object,
metatags: PropTypes.array,
scripts: PropTypes.array,
state: PropTypes.object,
Expand All @@ -122,6 +123,7 @@ HTMLDocument.propTypes = {

HTMLDocument.defaultProps = {
childrenContainerId: 'app',
htmlAttributes: {},
metatags: [],
scripts: [],
state: null,
Expand Down
10 changes: 10 additions & 0 deletions test/HTMLDocument.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ describe('HTMLDocument', () => {
expect(qs('title').html()).to.equal(props.title);
});

it('should render html attributes', () => {
const props = {
htmlAttributes: {
lang: 'es'
}
};
const qs = renderAndGetQuerySelector(props);
expect(qs('html').attr('lang')).to.equal(props.htmlAttributes.lang);
});

describe('Metatags', () => {
it('should render metatags', () => {
const props = {
Expand Down

0 comments on commit 434dcc0

Please sign in to comment.