Skip to content

Commit

Permalink
Render class instead of className
Browse files Browse the repository at this point in the history
  • Loading branch information
MicheleBertoli committed Oct 18, 2017
1 parent c207f68 commit 7c3a440
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ export default function renderToJSON(vnode, context, opts, inner) {
};

if (attributes) {
ret.props = omit(attributes, ['key', 'children']);
ret.props = omit(attributes, ['key', 'children', 'className']);

if (attributes.className && !attributes.class) {
ret.props.class = attributes.className;
}
}

if (attributes && attributes.key) {
Expand Down
22 changes: 22 additions & 0 deletions test/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { render } from '../src';
import { h } from 'preact';
import { expect } from 'chai';

describe('className / class massaging', () => {
it('should render class using className', () => {
let rendered = render(<div className="foo bar" />);
expect(rendered.props).to.have.property('class', 'foo bar');
expect(rendered.props).to.not.have.property('className');
});

it('should render class using class', () => {
let rendered = render(<div class="foo bar" />);
expect(rendered.props).to.have.property('class', 'foo bar');
});

it('should prefer class over className', () => {
let rendered = render(<div class="foo" className="foo bar" />);
expect(rendered.props).to.have.property('class', 'foo');
expect(rendered.props).to.not.have.property('className');
});
});

0 comments on commit 7c3a440

Please sign in to comment.