From 157a159283aed03f4f4b54884664feea25f6000c Mon Sep 17 00:00:00 2001 From: paldepind Date: Sat, 16 May 2015 12:39:29 +0200 Subject: [PATCH] Fix selector classes overriding property classes --- snabbdom.js | 6 ++++-- test/index.js | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/snabbdom.js b/snabbdom.js index 68b7c4c..d56eef8 100644 --- a/snabbdom.js +++ b/snabbdom.js @@ -70,7 +70,9 @@ function arrInvoker(arr) { } function updateProps(elm, oldVnode, vnode) { - var key, val, name, cur, old, oldProps = oldVnode.props, props = vnode.props; + var key, name, cur, old, oldProps = oldVnode.props, props = vnode.props, + val = props.className; + if (isUndef(oldProps) || val !== oldProps.className) elm.className = val; for (key in props) { val = props[key]; if (key === 'style' || key === 'class') { @@ -99,7 +101,7 @@ function updateProps(elm, oldVnode, vnode) { old[1] = val[1]; // captured in closure created with `arrInvoker` } } - } else if (key !== 'key') { + } else if (key !== 'key' && key !== 'className') { elm[key] = val; } } diff --git a/test/index.js b/test/index.js index f69450f..868f7c7 100644 --- a/test/index.js +++ b/test/index.js @@ -103,6 +103,12 @@ describe('snabbdom', function() { assert(elm.classList.contains('class')); assert(!elm.classList.contains('not')); }); + it('handles classes from both selector and property', function() { + var elm = createElm(h('i.has', {class: {classes: true}})); + console.log(elm.classList); + assert(elm.classList.contains('has')); + assert(elm.classList.contains('classes')); + }); it('can create elements with text content', function() { var elm = createElm(h('a', ['I am a string'])); assert.equal(elm.innerHTML, 'I am a string');