Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
props.className as an alias of props.class (#412)
Browse files Browse the repository at this point in the history
* Install attributes.className / props.className as a getter/setter proxy to `props.class`

* update tests
  • Loading branch information
developit authored Aug 4, 2017
1 parent f972b66 commit 3d0f2c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,20 @@ function applyEventNormalization({ nodeName, attributes }) {
}


function applyClassName({ attributes }) {
if (!attributes) return;
let cl = attributes.className || attributes.class;
if (cl) attributes.className = cl;
function applyClassName(vnode) {
let a = vnode.attributes || (vnode.attributes = {});
if (a.className) a.class = a.className;
Object.defineProperty(a, 'className', classNameDescriptor);
}


let classNameDescriptor = {
configurable: true,
enumerable: false,
get() { return this.class; },
set(v) { this.class = v; }
};

function extend(base, props) {
for (let key in props) {
if (props.hasOwnProperty(key)) {
Expand Down
2 changes: 1 addition & 1 deletion test/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ describe('jsx', () => {

let html = renderToString(jsx);

expect(html).to.equal('<div class="foo bar" data-foo="bar"><span id="some_id">inner!</span>ab</div>');
expect(html).to.equal('<div data-foo="bar" class="foo bar"><span id="some_id">inner!</span>ab</div>');
});
});

0 comments on commit 3d0f2c2

Please sign in to comment.