Skip to content

Commit

Permalink
Merge 86b9ddd into abd81b3
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Apr 23, 2019
2 parents abd81b3 + 86b9ddd commit 90334e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/diff/props.js
Expand Up @@ -10,11 +10,13 @@ import options from '../options';
* @param {boolean} isSvg Whether or not this node is an SVG node
*/
export function diffProps(dom, newProps, oldProps, isSvg) {
for (let i in newProps) {
if (i!=='children' && i!=='key' && (!oldProps || ((i==='value' || i==='checked') ? dom : oldProps)[i]!==newProps[i])) {
setProperty(dom, i, newProps[i], oldProps[i], isSvg);
let keys = Object.keys(newProps).sort();
for (let i = 0; i < keys.length; i++) {
if (keys[i]!=='children' && keys[i]!=='key' && (!oldProps || ((keys[i]==='value' || keys[i]==='checked') ? dom : oldProps)[keys[i]]!==newProps[keys[i]])) {
setProperty(dom, keys[i], newProps[keys[i]], oldProps[keys[i]], isSvg);
}
}

for (let i in oldProps) {
if (i!=='children' && i!=='key' && (!newProps || !(i in newProps))) {
setProperty(dom, i, null, oldProps[i], isSvg);
Expand Down
18 changes: 13 additions & 5 deletions test/browser/render.test.js
Expand Up @@ -254,6 +254,14 @@ describe('render()', () => {
expect(root.children[3]).to.have.property('value', '');
});

it('should set value inside the specified range', () => {
render(
<input type="range" value={0.5} min="0" max="1" step="0.05" />,
scratch
);
expect(scratch.firstChild.value).to.equal('0.5');
});

// IE or IE Edge will throw when attribute values don't conform to the
// spec. That's the correct behaviour, but bad for this test...
if (!/(Edge|MSIE|Trident)/.test(navigator.userAgent)) {
Expand Down Expand Up @@ -309,11 +317,11 @@ describe('render()', () => {
let div = scratch.childNodes[0];
expect(div.attributes.length).to.equal(2);

expect(div.attributes[0].name).equal('foo');
expect(div.attributes[0].value).equal('[object Object]');
expect(div.attributes[0].name).equal('bar');
expect(div.attributes[0].value).equal('abc');

expect(div.attributes[1].name).equal('bar');
expect(div.attributes[1].value).equal('abc');
expect(div.attributes[1].name).equal('foo');
expect(div.attributes[1].value).equal('[object Object]');
});

it('should apply class as String', () => {
Expand Down Expand Up @@ -991,7 +999,7 @@ describe('render()', () => {
render(<div id="a" />, scratch, childA);
expect(scratch.innerHTML).to.equal('<div id="a"></div><div id="b"></div><div id="c"></div>');
});

it('should render multiple render roots in one parentDom', () => {
const childA = scratch.querySelector('#a');
const childB = scratch.querySelector('#b');
Expand Down

0 comments on commit 90334e9

Please sign in to comment.